diff --git a/AuditPMML/readme.md b/AuditPMML/readme.md new file mode 100644 index 0000000..8776fab --- /dev/null +++ b/AuditPMML/readme.md @@ -0,0 +1,71 @@ +# PMML Audit Example + +## Purpose of This Example + +This example demonstrates how PMML functions can be invoked in **TIBCO BusinessEvents®**. +You can examine the project in TIBCO BusinessEvents Studio to understand the setup. +The scenario uses an audit data dataset from the PMML examples at: +http://dmg.org/pmml/pmml_examples/index.html#Audit + +--- + +## How to Run the Example + +1. Open a command window and at the command prompt, start the TIBCO BusinessEvents engine using the following command. Substitute your actual value for `BE_HOME`. + + ```bash + cd BE_HOME/examples/standard/Analytics/AuditPMML + BE_HOME/bin/be-engine --propFile BE_HOME/bin/be-engine.tra -u default -c AuditPMML/Deployments/pmml.cdd AuditPMML.ear + ``` + + > Adapt these commands as needed, for example, if you have customized the example project or are running it from a different directory. + +2. Create a fictional client using the following data and send it to the server. Change the values and repeat this step to send multiple events, as desired. + + **Event Path:** `/Events/ClientData` + **Send To:** `http://localhost:8308/Channels/HTTP/ClientData` + + Example `curl` command to send this data: + + ```bash + curl -X POST http://localhost:8308/Channels/HTTP/ClientData \ + -H "Content-Type: application/json" \ + -d '{ + "Age": 20, + "Employment": "Private", + "Education": "College", + "Marital": "Unmarried", + "Occupation": "Service", + "Income": 81838, + "Gender": "Female", + "Deductions": 0, + "Hours": 72 + }' + ``` + + In the command window, you will see the predicted output from the model: + + ``` + Target=0, Age=20, Employment=Private, Education=College, Marital=Unmarried, Occupation=Service, Income=81838.0, Gender=Female, Deductions=0.0, Hours=72 + ``` + +3. If you want to predict the target field for all the data in the `Audit.csv` file, send the following event. The output is written to `out.csv` with the predicted target value. + + **Event Path:** `/Events/LoadBulkData` + **Send To:** `http://localhost:8308/Channels/HTTP/LoadBulkData` + + Example `curl` command: + + ```bash + curl -X POST http://localhost:8308/Channels/HTTP/LoadBulkData \ + -H "Content-Type: application/json" \ + -d '{}' + ``` + + The output is written to the CSV file: + + ``` + BE_HOME/examples/standard/Analytics/AuditPMML/resources/out.csv + ``` + +--- diff --git a/CassandraCatalog/readme.md b/CassandraCatalog/readme.md new file mode 100644 index 0000000..c2a06c2 --- /dev/null +++ b/CassandraCatalog/readme.md @@ -0,0 +1,178 @@ +# Cassandra Store Catalog Functions Example + +## Purpose of This Example + +This example demonstrates the use of various Store Catalog functions APIs to provide communication with the Cassandra store. + +Features covered: + +* Fetching metadata of the configured store +* Put/Get/Delete/Query operations on Entities (Concept/Events) against the store +* Manual creation of items and performing Put/Get/Delete/Query on them against the store +* Running store operations within a transaction + +**Note:** The application uses Store APIs and can be used with external **Apache Cassandra**. + +--- + +## Pre-requisites + +* Install Apache Cassandra server (Apache Cassandra 4.x and above) - (To run this example with Apache Cassandra) + +--- + +## How to Run the Example + +1. **Update** `be-engine.tra` and `studio.tra` (`BE_HOME/studio/eclipse/configuration/studio.tra`). + +2. **Setup Apache Cassandra store (To run this example with Apache Cassandra).** + + * Implementation of Cassandra Store Catalog functions is available at: + [https://github.com/TIBCOSoftware/be-contribution/tree/main/catalog/cassandra-catalog-fn](https://github.com/TIBCOSoftware/be-contribution/tree/main/catalog/cassandra-catalog-fn) + * Build the project as mentioned in: + [https://github.com/TIBCOSoftware/be-contribution/tree/main/catalog/README.md](https://github.com/TIBCOSoftware/be-contribution/tree/main/catalog/README.md) (using Maven goal `install`) + * The generated `cassandra-catalog-fn-X.X.X.jar` will be available inside the `target` directory. + * Start BusinessEvents Studio and open your project. + * Add `cassandra-catalog-fn-X.X.X.jar` to your Build Path. This enables the new catalog functions inside **Catalog Functions -> Custom Functions** view in Studio. + +3. **Start Apache Cassandra store** + + ```bash + # Change directory + cd be-samples-dir/standard/CassandraCatalog/scripts + + # Make sure your Apache Cassandra server is running. + + # Create keyspace 'storefunctions' with user credentials be_user/BE_USER. + + # Execute CQL script: + $CASSANDRA_HOME/bin/cqlsh -k storefunctions -f ./storefunctions.cql + ``` + +4. **Start the TIBCO BusinessEvents engine** + + ```bash + cd be-samples-dir/CassandraCatalog + + BE_HOME/bin/be-engine --propFile BE_HOME/bin/be-engine.tra -u default -c CassandraCatalog/Deployments/Cassandra.cdd CassandraCatalog.ear + ``` + + Adapt the command as needed, e.g., if you have customized the example project or run it from a different directory. + +--- + +## Usage and `curl` Requests + +### 1. Show Store Metadata + +Show the store metadata by sending an empty POST request. + +```bash +curl -X POST \ + http://localhost:4545/Channels/HTTPChannel/metadata \ + -H "Content-Type: application/json" \ + -d '{}' +``` + +--- + +### 2. Create Employee (Put Employee) + +Create an employee with the following details: + +```bash +curl -X POST \ + http://localhost:4545/Channels/HTTPChannel/put \ + -H "Content-Type: application/json" \ + -d '{ + "name": "Bob", + "age": 25, + "isPermanant": true, + "salary": 500.00, + "homePhone": "212-313-4114", + "mobilePhone": "400-300-4000", + "address": "Palo Alto, California", + "alternateAddress": "Mountain View, California", + "departments": "Sales, HR" + }' +``` + +--- + +### 3. Get Employee Details + +Get details for an employee by `empId`. Optionally include `addressId` and `phoneId` to retrieve associated entities. + +```bash +curl -X POST \ + http://localhost:4545/Channels/HTTPChannel/get \ + -H "Content-Type: application/json" \ + -d '{ + "empId": "679241819293221", + "addressId": "679241818009414,679241818947365", + "phoneId": "679241819072128" + }' +``` + +* To fetch only employee details (without address and phone): + +```bash +curl -X POST \ + http://localhost:4545/Channels/HTTPChannel/get \ + -H "Content-Type: application/json" \ + -d '{"empId": "679241819293221"}' +``` + +--- + +### 4. Query Employee Details + +Query employees based on filter criteria (e.g., age > 20): + +```bash +curl -X POST \ + http://localhost:4545/Channels/HTTPChannel/query \ + -H "Content-Type: application/json" \ + -d '{"age": 20}' +``` + +--- + +### 5. Delete Employee + +Delete an employee and optionally associated entities by IDs: + +```bash +curl -X POST \ + http://localhost:4545/Channels/HTTPChannel/delete \ + -H "Content-Type: application/json" \ + -d '{ + "empId": "679241819293221", + "addressId": "679241818009414,679241818947365", + "phoneId": "679241819072128" + }' +``` + +--- + +### 6. Phone Transaction + +Perform phone-related operations within a transaction: + +```bash +curl -X POST \ + http://localhost:4545/Channels/HTTPChannel/phoneTransaction \ + -H "Content-Type: application/json" \ + -d '{}' +``` + +--- + +## Notes + +* Replace IDs like `"679241819293221"` with actual IDs from your data. +* The server is assumed to be running locally on port `4545`. +* Modify the JSON payloads to fit your real use case. +* Ensure your Apache Cassandra server and TIBCO BusinessEvents engine are running before making these requests. + +--- diff --git a/FraudDetectionLiveView/readme.md b/FraudDetectionLiveView/readme.md new file mode 100644 index 0000000..9d77b5c --- /dev/null +++ b/FraudDetectionLiveView/readme.md @@ -0,0 +1,158 @@ + +# Fraud Detection LiveView + +## Purpose of This Example + +This example builds on the Fraud Detection example by adding live monitoring, alerting, and aggregation using LiveView. + +Fraud is suspected when: +- More than three debit transactions occur in a two-minute window. + +The account is moved from **Normal** to **Suspended** in two cases: +- When 3 fraud detection attempts happen. +- If the account balance becomes negative. + +> Note: This example uses clustered deployment with cache object management. For unclustered deployments: +> - Replace all `Cluster.DataGrid.CacheLoadConceptByExtId` calls with `Instance.getByExtId`. +> - Update CDD cluster and object management configs accordingly. + +--- + +## Pre-requisites + +- TIBCO StreamBase 10.x installed (download from TIBCO eDelivery). +- Basic LiveView Datamart knowledge. + +--- + +## How to Run the Example + +### 1. Start LiveView Server + +- Linux/Mac: + Set `JAVA_HOME`, then go to `SB_HOME/distrib/tibco/bin`. Use `epadmin` to manage nodes. + Refer to [StreamBase docs](https://docs.tibco.com/pub/str/10.6.0/doc/html/install/configure-shell.html). + +- Windows: + Run `sbd.exe` from a StreamBase Command Prompt. + +- Install and start the node: + +```bash +cd SB_HOME/distrib/tibco/bin +epadmin install node nodename=A.fdlv-dep application={path_to_application.zip} nodedirectory={path_to_logs_dir} +epadmin servicename=fdlv-dep start node +```` + +* Check logs at `{nodedirectory}/A.fdlv-dep/logs/*.log` for "all tables loaded". + +* Access LiveView web UI at: [http://localhost:10080/lvweb](http://localhost:10080/lvweb) + If it doesn’t load, check node port: + +```bash +epadmin display services --servicetype=liveview +``` + +--- + +### 2. Start TIBCO BusinessEvents Engine + +Open a terminal and run: + +```bash +cd BE_HOME/examples/metrics/FraudDetectionLiveView/FraudDetectionLiveView +BE_HOME/bin/be-engine --propFile BE_HOME/bin/be-engine.tra -u default -c FraudDetectionLiveView/FraudDetectionLiveView.cdd FraudDetectionLiveView.ear +``` + +--- + +### 3. Create an Account + +Send a CreateAccount event with: + +```bash +curl -X POST http://localhost:8109/Channels/HTTP/AllOps \ + -H "Content-Type: application/json" \ + -d '{ + "AccountId": "Bob", + "Balance": 20000, + "AvgMonthlyBalance": 11000, + "City": "Palo Alto", + "State": "CA", + "event": "CreateAccount" + }' +``` + +Expected response in BE engine logs: + +* `#### Created account Bob.` +* Or if duplicate: `#### Account already exists: Bob` + +--- + +### 4. Debit the Account + +Send a Debit event: + +```bash +curl -X POST http://localhost:8109/Channels/HTTP/AllOps \ + -H "Content-Type: application/json" \ + -d '{ + "AccountId": "Bob", + "Amount": 2000, + "event": "Debit" + }' +``` + +Example log messages: + +| Action | Message | +| ------------------------------------------- | -------------------------------------------------------------- | +| Debit amount less than balance | `#### Debiting account Bob by $2000.0` | +| Debit amount greater than balance | `#### Account ID Bob STATUS set to Suspended. Balance <0` | +| Debit suspended account | `#### Cannot debit the suspended account Bob` | +| 3 debits within 2 minutes - fraud suspected | `#### Account ID Bob. Fraud suspected, Attempt [1]` | +| After 3 fraud attempts, account suspended | `#### Account ID Bob STATUS set to Suspended. Fraud detected.` | + +--- + +### 5. Unsuspend the Account (Optional) + +Send an Unsuspend event: + +```bash +curl -X POST http://localhost:8109/Channels/HTTP/AllOps \ + -H "Content-Type: application/json" \ + -d '{ + "AccountId": "Bob", + "event": "Unsuspend" + }' +``` + +Expected log message: + +* `#### Account ID Bob STATUS set to Normal.` + +--- + +### 6. Monitor LiveView Web + +Perform operations and observe charts updating live at [http://localhost:10080/lvweb](http://localhost:10080/lvweb) + +--- + +### 7. Reset Data + +Restart the engine to reset the cache and data. + +--- + +### 8. Stop LiveView Servers + +For SB 10.x: + +```bash +epadmin servicename=fdlv-dep stop node +epadmin servicename=fdlv-dep remove node +``` + diff --git a/FraudDetectionStreamBase/readme.md b/FraudDetectionStreamBase/readme.md new file mode 100644 index 0000000..5f3ad4b --- /dev/null +++ b/FraudDetectionStreamBase/readme.md @@ -0,0 +1,111 @@ + +# StreamBaseChannel - TIBCO BusinessEvents® Example + +## Purpose of This Example + +This example demonstrates how the **StreamBase channel** integrates **TIBCO BusinessEvents®** with **TIBCO StreamBase® CEP**. + +Fraud detection is triggered when: + +* An account has **more than 3 debits** in **2 minutes**, and +* The **total of those debits exceeds 80%** of the average monthly balance. + +> **Note:** Use **Chrome** or **Firefox** to view the HTML form with the "Send" button. + +--- + +## How to Run the Example + +> **Requirements**: +> +> * TIBCO BusinessEvents +> * TIBCO StreamBase + +--- + +### 1. Start StreamBase Application + +Launch StreamBase as appropriate (via command line or StreamBase Studio). +See: [StreamBase Test/Debug Guide](https://docs.tibco.com/pub/str/10.6.0/doc/html/testdebug/index.html) + +--- + +### 2. Start BusinessEvents Engine + +```bash +cd /examples/standard/FraudDetectionStreamBase +/bin/be-engine --propFile /bin/be-engine.tra -u default -c FraudDetectionStreamBase/fdsb.cdd fdsb.ear +``` + +> Replace `` with your actual installation path. + +--- + +## Interacting via HTTP (cURL) + +The HTTP channel is exposed at: + +``` +http://localhost:8108/Channels/HTTP/AllOps +``` + +### 3. Create an Account + +```bash +curl -X POST http://localhost:8108/Channels/HTTP/AllOps \ + -H "Content-Type: application/json" \ + -d '{ + "_eventType": "/Events/CreateAccount", + "AccountId": "Bob", + "Balance": 10000, + "AvgMonthlyBalance": 20000 + }' +``` + +> Expected response in logs: + +```text +#### Created account Bob. +``` + +--- + +### 4. Debit the Account + +```bash +curl -X POST http://localhost:8108/Channels/HTTP/AllOps \ + -H "Content-Type: application/json" \ + -d '{ + "_eventType": "/Events/Debit", + "AccountId": "Bob", + "Amount": 2000 + }' +``` + +> Expected response: + +```text +#### Debiting account Bob by $2000.0 +``` + +--- + +## Behavior Scenarios + +| Scenario | Example | Response | +| ----------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | +| Create the same account twice | Repeat the create cURL | `#### Account already exists: Bob` | +| Debit exceeds balance | Amount > Balance | `#### Account ID Bob STATUS set to Suspended. Balance -1000.0 is less than zero` | +| Debit suspended account | Any debit after above | `#### Cannot debit the suspended account Bob` | +| Trigger fraud detection | 3+ debits in 2 mins and total > 80% of AvgMonthlyBalance | `#### Account ID Bob STATUS set to Suspended. Reason: 80.0% of monthly average exceeded in 120 seconds` | + +--- + +### 5. Reset the Engine + +To reset the data/facts, **restart the BusinessEvents engine**: + +```bash +# Example (from project directory) +/bin/be-engine --propFile /bin/be-engine.tra -u default -c FraudDetectionStreamBase/fdsb.cdd fdsb.ear +``` diff --git a/FraudDetectionTerr/readme.md b/FraudDetectionTerr/readme.md new file mode 100644 index 0000000..7d207a6 --- /dev/null +++ b/FraudDetectionTerr/readme.md @@ -0,0 +1,120 @@ + +# Fraud Detection TERR - TIBCO BusinessEvents® Example + +## Overview + +This example demonstrates a **Fraud Detection** scenario using **TIBCO BusinessEvents®** with **TIBCO Enterprise Runtime for R (TERR)**. + +Fraud detection is a commonly used Complex Event Processing (CEP) use case, as it highlights how a CEP engine can correlate multiple events over time using windows and threshold logic. + +Fraud is suspected when **either** of the following conditions is met: + +* The account incurs **more than three debit transactions** in a **two-minute period**. +* The **total of the debits** within two minutes exceeds **80% of the average monthly balance** of the account. + +**Note:** Use Google Chrome or Mozilla Firefox to view the Send Button if using the original `readme.html` interface. + +--- + +## Prerequisites + +Before running this example, update the following environment variable in the BusinessEvents engine configuration: + +```properties +tibco.env.TERR_HOME +``` + +Set this in: + +``` +/bin/be-engine.tra +``` + +Ensure it points to your **TERR installation** directory. + +--- + +## Running the Example + +### 1. Start the BusinessEvents Engine + +Open a terminal and run the following command: + +```bash +cd /examples/standard/FraudDetectionTerr +/bin/be-engine --propFile /bin/be-engine.tra -u default -c FraudDetectionTerr/fdterr.cdd fdterr.ear +``` + +> Replace `` with your actual TIBCO BusinessEvents installation path. +> Adjust the command as needed if you have modified the example or are using a different working directory. + +--- + +## Sending Events via HTTP (Using `curl`) + +The HTTP channel for this example listens on: + +``` +http://localhost:8117/Channels/HTTP/AllOps +``` + +### 2. Create an Account + +```bash +curl -X POST http://localhost:8117/Channels/HTTP/AllOps \ + -H "Content-Type: application/json" \ + -d '{ + "_eventType": "/Events/CreateAccount", + "AccountId": "Bob", + "Balance": 20000, + "AvgMonthlyBalance": 11000 + }' +``` + +Expected log output: + +``` +#### Created account Bob. +``` + +--- + +### 3. Debit the Account + +```bash +curl -X POST http://localhost:8117/Channels/HTTP/AllOps \ + -H "Content-Type: application/json" \ + -d '{ + "_eventType": "/Events/Debit", + "AccountId": "Bob", + "Amount": 2000 + }' +``` + +Expected log output: + +``` +#### Debiting account Bob by $2000.0 +``` + +--- + +## Example Behaviors and Rule Responses + +| Action | System Response | +| --------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | +| Create the same account twice | `#### Account already exists: Bob` | +| Debit amount exceeds balance | `#### Account ID Bob STATUS set to Suspended. Balance -1000.0 is less than zero` | +| Debit a suspended account | `#### Cannot debit the suspended account Bob` | +| Trigger fraud (3+ debits in 2 minutes and total > 80% of average monthly balance) | `#### Account ID Bob STATUS set to Suspended. Fraud suspected` | + +--- + +## Resetting the Application State + +To reset data and start a new test run, restart the engine: + +```bash +cd /examples/standard/FraudDetectionTerr +/bin/be-engine --propFile /bin/be-engine.tra -u default -c FraudDetectionTerr/fdterr.cdd fdterr.ear +``` diff --git a/KinesisChannel/readme.md b/KinesisChannel/readme.md new file mode 100644 index 0000000..161608c --- /dev/null +++ b/KinesisChannel/readme.md @@ -0,0 +1,72 @@ + +# KinesisChannel – TIBCO BusinessEvents® Example + +## Overview + +This example demonstrates how **TIBCO BusinessEvents®** integrates with **Amazon Kinesis** using the Kinesis Channel. It shows how BusinessEvents can **send** and **receive** event data via AWS Kinesis streams. + +You can explore the configuration and logic in **TIBCO BusinessEvents Studio** for implementation details. + +--- + +## Project Description + +* The **Producer Agent** sends data records (events) to a Kinesis data stream. +* The **Consumer Agent** subscribes to the Kinesis stream and processes incoming stock events. +* The producer is triggered at regular intervals. +* The consumer processes each `StockEvent` using the `ProcessStockRule`. + +--- + +## Requirements + +* AWS Account with permissions to create and access **Kinesis Data Streams**. +* Kinesis Streams configured appropriately. +* IAM User and Policy set up with access keys for BusinessEvents Kinesis integration. +* All required AWS and Kinesis properties configured in the `.cdd` file of the project. + +--- + +## How to Run the Example + +### 1. Set up AWS Resources + +* Create a **Kinesis data stream** in AWS. +* Create an **IAM user** and **policy** that allows access to the Kinesis stream. +* Obtain AWS Access Key and Secret Key and configure them in the `.cdd`. + +### 2. Start the Consumer Agent + +```bash +cd /examples/standard/KinesisChannel +/bin/be-engine --propFile /bin/be-engine.tra -u consumer -c KinesisChannel/kinesis.cdd KinesisChannel.ear +``` + +### 3. Start the Producer Agent + +```bash +cd /examples/standard/KinesisChannel +/bin/be-engine --propFile /bin/be-engine.tra -u producer -c KinesisChannel/kinesis.cdd KinesisChannel.ear +``` + +--- + +## Sample Output + +### Consumer Agent Output + +``` +#### Stock Details Received - Ticker Symbol: NVDA Trade Type: BUY +#### Stock Details Received - Ticker Symbol: APPL Trade Type: SELL +... +``` + +Additional debug logs will show rule processing and shard checkpointing. + +### Producer Agent Output + +``` +#### Stock Details Sent - Ticker Symbol: NVDA Trade Type: BUY +#### Stock Details Sent - Ticker Symbol: APPL Trade Type: SELL +... +``` diff --git a/LiveScore/readme.md b/LiveScore/readme.md new file mode 100644 index 0000000..00155ea --- /dev/null +++ b/LiveScore/readme.md @@ -0,0 +1,99 @@ +# LiveScore – TIBCO BusinessEvents® Example + +## Overview + +This example demonstrates how to use **TIBCO BusinessEvents®** to send a SOAP-based request to **LiveScore** for executing a predictive model using test data. The request is constructed using event properties and sent via the HTTP channel to the LiveScore API. + +The response returned from LiveScore contains the model’s prediction based on the submitted event data. + +--- + +## Prerequisites + +* TIBCO BusinessEvents® installed +* LiveScore server deployed and accessible +* EAR file located in the correct example directory + +--- + +## Project Purpose + +* Send a sample **Statistica Event** from BusinessEvents to LiveScore via HTTP +* Receive a **prediction response** from LiveScore, based on a preconfigured workflow (WFID) + +--- + +## How to Run the Example + +### 1. Start the BusinessEvents Engine + +Open a terminal or command prompt and execute: + +```bash +cd /examples/standard/Analytics/LiveScore +/bin/be-engine --propFile /bin/be-engine.tra -u default -c LiveScore/LiveScore.cdd LiveScore.ear +``` + +> Replace `` with your actual TIBCO BusinessEvents installation directory. + +--- + +### 2. Send a Statistica Event to Trigger LiveScore Evaluation + +This event triggers the LiveScore workflow and returns a prediction result. + +#### Sample `curl` Command (HTTP Request): + +```bash +curl -X POST http://localhost:8108/Channels/HTTP/StatisticaOps \ + -H "Content-Type: application/json" \ + -d '{ + "_eventType": "/Events/StatEvent", + "ClearCache": "1", + "Duration_of_Credit": "36", + "Purpose_of_Credit": "retraining", + "Amount_of_Credit": "3003", + "Marital_Status": "single", + "Gender": "female", + "Age": "32", + "Occupation": "skilled employee", + "Credit_Rating": "good", + "Living_in_Current_Household_for": "5-8 years", + "WFID": "/Template/CreditScoring_WoE_Example" + }' +``` + +> Ensure the port number (`8108`) and endpoint (`/Channels/HTTP/StatisticaOps`) match your actual HTTP channel configuration in the `.cdd`. + +--- + +### 3. Observe the Output + +When the event is processed, you will see console output similar to: + +``` +Sending Statistica Event +Answer received from the event is: { ... } +``` + +The returned JSON contains the prediction or scoring result from LiveScore. + +--- + +### 4. Reset Data + +To reset the example, stop and restart the BE engine: + +```bash +/bin/be-engine ... +``` + +--- + +## Notes + +* Make sure the `WFID` points to a valid LiveScore workflow that exists and is deployed. +* Adjust HTTP properties or the BE `.cdd` file if your deployment environment differs from the example. +* This example uses SOAP over HTTP. Ensure your LiveScore server supports this interface and has CORS or security configurations if needed. + +--- diff --git a/MQTTChannel/readme.md b/MQTTChannel/readme.md new file mode 100644 index 0000000..aada11c --- /dev/null +++ b/MQTTChannel/readme.md @@ -0,0 +1,134 @@ +# MQTT Channel – TIBCO BusinessEvents® Example + +## Overview + +This example demonstrates how **TIBCO BusinessEvents®** uses the **MQTT channel** to send and receive events. The example simulates temperature control across different building floors using MQTT-based communication between a publisher and BusinessEvents agents. + +--- + +## Use Case + +Imagine a building with multiple floors where each floor can have its temperature set. This project simulates: + +* A mobile app or device publishing "SetTemperature" events via MQTT. +* BusinessEvents subscribing to floor-specific topics, processing the event, and replying. +* A demonstration of request-reply behavior using `Event.requestEvent` and `Event.replyEvent`. + +--- + +## Requirements + +* A local or accessible MQTT broker at `tcp://localhost:1883` +* TIBCO BusinessEvents installed +* MQTT Java client library (`mqtt-1.0.0.jar`) placed at `BE_HOME/lib/ext/tpcl/contrib/` + +--- + +## Running the Basic Example (Publish-Subscribe) + +### 1. Start MQTT Broker + +Ensure that a broker is running locally on port `1883`. + +### 2. Start the Client Agent + +```bash +cd BE_HOME/examples/standard/MQTTChannel +BE_HOME/bin/be-engine --propFile BE_HOME/bin/be-engine.tra -u client -c MQTTChannel/mqtt.cdd MqttChannel.ear +``` + +### 3. Compile and Run the Publisher + +```bash +cd BE_HOME/examples/standard/MQTTChannel +javac -cp BE_HOME/lib/ext/tpcl/contrib/mqtt-1.0.0.jar -d . TemperaturePublisher.java +java -cp .:BE_HOME/lib/ext/tpcl/contrib/mqtt-1.0.0.jar com.tibco.mqtt.samples.TemperaturePublisher firstfloor +``` + +> To use a different broker URL: + +```bash +java -cp .:BE_HOME/lib/ext/tpcl/contrib/mqtt-1.0.0.jar com.tibco.mqtt.samples.TemperaturePublisher firstfloor tcp:// +``` + +--- + +### Sample Output from Client Agent + +```text +SetTemperature rule triggered +Setting floor temperature and notifying +SetTemperature rule complete +ReceiveNotify rule triggered +Received message is - Temperature set +ReceiveNotify rule complete +``` + +--- + +## Running the Example with Request/Reply Pattern + +This demonstrates how to use `requestEvent` and `replyEvent`. + +### 1. Start MQTT Broker (if not already running) + +Ensure the broker is available at `tcp://localhost:1883`. + +### 2. Start the Client Agent + +```bash +cd BE_HOME/examples/standard/MQTTChannel +BE_HOME/bin/be-engine --propFile BE_HOME/bin/be-engine.tra -u client -c MQTTChannel/mqtt.cdd MqttChannel.ear +``` + +### 3. Start the Server Agent (with unique client ID) + +Use a separate `client.properties` file to define a different MQTT client ID. + +```bash +cd BE_HOME/examples/standard/MQTTChannel +BE_HOME/bin/be-engine --propFile BE_HOME/bin/be-engine.tra -u server -c MQTTChannel/mqtt.cdd -p client.properties MqttChannel.ear +``` + +### 4. Run the Publisher for Second Floor + +```bash +cd BE_HOME/examples/standard/MQTTChannel +javac -cp BE_HOME/lib/ext/tpcl/contrib/mqtt-1.0.0.jar -d . TemperaturePublisher.java +java -cp .:BE_HOME/lib/ext/tpcl/contrib/mqtt-1.0.0.jar com.tibco.mqtt.samples.TemperaturePublisher secondfloor +``` + +> Or specify a different broker: + +```bash +java -cp .:BE_HOME/lib/ext/tpcl/contrib/mqtt-1.0.0.jar com.tibco.mqtt.samples.TemperaturePublisher secondfloor tcp:// +``` + +--- + +### Sample Output + +#### Client Agent + +```text +RequestEvent rule triggered +Requesting Event +Temperature set in reply event rule +RequestEvent rule complete +``` + +#### Server Agent + +```text +ReplyEvent rule triggered +Setting floor temperature and replying +ReplyEvent rule complete +``` + +--- + +## Additional Notes + +* MQTT topics and broker URL can be configured in the `.cdd` file or via Global Variables. +* Use a different MQTT client ID for each BusinessEvents agent connecting to the broker. +* Ensure the publisher is targeting the correct topic (`firstfloor`, `secondfloor`, etc.)