Jump to content
  • How to create a publish/subscribe example with TIBCO BusinessWorks? 6 and TIBCO FTL®


    Bill Mclane

    Table of Contents

    Introduction

    This tutorial describes how to build a publish/subscribe example using TIBCO BusinessWorks? 6 and TIBCO FTL®. Lets take a simple use case for an order handling process. The first step in the process is to create a new order, then the order must be sent to three different applications for processing, lets call these applications A, B and C. Applications A and B need to process all orders, whilst application C only needs to process orders of type ?XYZ?. The message flow for this process can be depicted as shown below.

    orderflow_1.thumb.jpg.dacf6730d0970a603b076ab1c3565207.jpg

    Before we start lets look at what tools we are going to use to build this example. TIBCO BusinessWorks? 6 will be used as the application development tool to model and execute the order handling process, TIBCO FTL® is used as the underlying messaging layer between the various components.

    Note, some working knowledge of these tools is required to build this tutorial in your own environment. The attached pre-built examples can also be downloaded for reference.

    The example in this tutorial uses the following products:

    • TIBCO FTL® 5.2 Hotfix 1
    • TIBCO FTL® 5.0 Client
    • TIBCO ActiveMatrix BusinessWorks? 6.3.5 (requires TIBCO FTL® 5.0 client)

    We?ll be using two graphical tools in building this example. The FTL Realm Server is used for defining how the various application components will communicate together, and BusinessStudio is used to build and execute the application processing logic for each component.

    Defining the communication pattern

    Firstly, ensure your FTL Realm Server is running. See running tibrealmserver in the FTL docs: Realm Server Executable Reference

    To access the Realm Server UI open a browser and navigate to the appropriate URL, for a local server with default configuration go to http://localhost:8080

    We?ll create FTL applications to represent the order producing and receiving sides of the order handling process.

    Turn on edit mode then go to the applications page and select the ?+? to create the two new applications:

    • OrderProducerApp
    • OrderConsumerApp

    Next, we?ll create an ?endpoint? for each FTL application and a transport to connect these endpoints together to enable the communication. 


    Note, FTL is extremely flexible in how data can be distributed with a wide variety of transport options available for many different use cases. An endpoint is an abstraction used by the application components to insulate them from the communication transport details. These transport details can be changed by administration staff to easily support different deployment models without the need to change any application logic.


    Create two endpoints:

    • OrderProducerEP
    • OrderConsumerEP

    Note, for this simple example we?ll share the same FTL consumer application and endpoint definition for the three receiving components. However in a real use case you may prefer to separate these to each have its own application and endpoint definitions, particularly if the components are located in different environments that may involve different communication transports being used.

    Your Applications screen should look as follows:

    rs-apps1_0.thumb.png.be30c7799e0b8256691c647034ab3fe3.png

    Now create transports for the underlying communication mechanism, we?ll choose dynamic TCP transports so the components can be easily deployed to different hosts. We?ll create two transports that work together in a client/server mode, the receiving components will use the client or ?connect? side and the sending side will use the server or ?listen? side. This allows us to easily connect additional receiving components in future if required.

    Go to the transports page and select the ?+? to create two new transports, as follows:

    • OrderProducerTP, Type:DynamicTCP, Mode:Listen
    • OrderConsumerTP, Type:DynamicTCP, Mode:Connect

    Ensure you configure the two transports as part of the same transport group so they work correctly together, the transport page should look as follows:

    rs-tports1.thumb.png.d5392473f3d6c40870918c71b1d42889.png

    Now return to the Applications page and configure the transports to connect up the endpoints, the screen should look as follows:

    rs-apps2.thumb.png.ae0dc66e00316931eeeac498e9ab2b79.png

    Next, we?ll create a message format to define the message structure for the order message.

    Go to the Formats page and select the ?+? to create a new Format, name the format ?Order?, and add the following fields:

    • OrderID: Long
    • OrderType: String
    • OrderDetails: String

    rs-format.thumb.png.ab8b44aa1220549ead2ec37d2184d265.png

    Now ensure to enable this message format to be used by the application components. Go back the the Applications page and view the application's details by clicking the ??? for each application. On the details page select the Order format so its added to the list of preloaded formats, and click save.

    rs-preload.thumb.png.084accacb130d902ac36aa8552326f7b.png

    We?ve now completed the necessary configuration steps to define the communication for our order processing components, but before the configuration can be used we need to deploy the changes. Click the orange Deploy icon at the top of the page and verify all changes have been successfully deployed. 

    rs-deploy.thumb.png.e35662badcf43fdf6c48d8cf4560aedb.png

    Building the application logic

    Open the BusinessStudio editor and create a new BusinessWorks project, for example called MyOrderProject.

    Create two new FTL Realm Server Connection resources, one for each FTL application. Configure the Realm Server URL and browse to select the appropriate application name.

    bw-rs.thumb.png.23138609f017d354622096b8d9faed7d.png

    Create a new BusinessWorks process called CreateOrder and add the following activities:

    • Timer activity, configure the activity to run once a second
    • FTL Publisher

    bw-prod.thumb.png.c54f7b8d877914410fe019df4122fd18.png

     

    Connect the activities together and configure the FTL Publisher as follows:

    • Set the FTL Ream Server Connection to the producer?s connection resource
    • Browse and select the OrderProducerEP
    • Choose Format as Predefined and browse to select the Order Format
    • Configure the publisher input parameters for example as shown below.

    bw-input.thumb.png.0fea1e33ef8c0f2d8e983acf28f0a14e.png

     

    We can test the producer process by using an FTL sample program to receive the messages sent by the BusinessWorks producer. For example, follow the notes in the <FTL Home>/5.2/samples and run the tibrecvex sample, then launch the BusinessStudio debugger to run the order producer process. Ensure you pass the tibrecvex program a valid FTL consumer application and endpoint name, check the sample receives the order messages.

    ftl-test.thumb.png.b8c316b57506a86d97aa525c29ff72f1.png

     

    Now lets complete the BusinessWorks project and create the BusinessWorks processes to receive the orders. Create a new BusinessWorks process called ReceiveOrderA and add the following activities:

    • FTL Subscriber
    • Log

    ft-sub.thumb.png.f2a4a1a8a8c25e7961861c55166142fb.png

    Connect the activities together and configure the FTL Subscriber as follows:

    • Set the FTL Ream Server Connection to the consumer?s connection resource
    • Browse and select he OrderConsumerEP
    • Choose Format as Predefined and browse to select the Order Format
    • Configure the Log?s input parameters for example as shown below

    bw-log.thumb.png.2efcf3ffd20a5da5f92a11a8d29085c7.png

    Follow the same procedure to create another BusinessWorks process for receiver B, and again for receiver C.

    For receiver C we?ll configure a content matcher to ensure it only receives orders of type ?XYZ?. This is done using a JSON syntax string of the form { "fieldname1" : value1 , ... , "fieldnameN" : valueN } for this case we want the simple matcher: {"OrderType":"XYZ"}

    Note, since the field type is a string the value must be enclosed in quotes.

    bw-matcher.thumb.png.ff7b4b84f0719d5aa949fef1a967cfee.png

    Now we?re ready to test the project, launch the debugger and check the console output, ensure receivers A and B receive both order types whilst receiver C only receives orders of type ?XYZ?.

    bw-console.thumb.jpg.cf101a90d50b943f436fabab3e3756b5.jpg

     

    Adding delivery assurance

    For most fire and forget scenarios you?ll want to provide some assurance that messages will arrive at their intended destinations. This can be achieved in FTL with an out of band in-memory based persistence cluster. In this example we?ll create a cluster with a single server, for production systems a persistence cluster would comprise of a quorum of servers, typically 3.

    To configure persistence go back the Realm Server UI and reenter edit mode. Go to the Clusters page and select the ?+? to create a cluster. Create a cluster called ?cluster? and single server called ?pserver?. Select Dynamic TCP as the protocol for the cluster and client communication.

    rs-cluster.thumb.jpg.7290cdd921591a0cc329324f631cb02e.jpg

     

    Next we need to create a message store for our order example; go to the Stores page and select the ?+? to create a new message store. Name the store ?OrderStore? and assign it to our persistence cluster. Choose Publisher Mode Store->Confirm->Send for the highest assurance level, this ensures the message is not published until it has been safely persisted in the message store.

    Next we need to configure three durables, one for each order receiving component. Click on the ??? above the store name to create the durables; DurableA, DurableB, DurableC. For Durable Type choose ?Static/Standard?, Acknowledgement Mode ?sync? and for Durables A&B Interest ?store all messages?. For Durable C choose Interest ?store matching messages? and specify a match field for OrderType with value XYZ. Your store configuration should now look as below:

    rs-store.thumb.jpg.b7528ee3c433539f7db2813ed6cf18f0.jpg

     

    Now we need to enable the message store to be used with our order endpoints. Go to the Applications page and for each endpoint select the OrderStore from the drop down.

    Now deploy the changes made and check the deployment is successful.

    Before we can retest the application we need to start the FTL persistence server, run the tibstore executable from the FTL installation for example:

     tibstore -n pserver -d data_dir -rs http://localhost:8080

    Refer to tibstore Command Line Reference for details.

     

    Return to the BusinessWorks designer studio and for each receiver process configure the appropriate durable name on the FTL Subscriber?s Advanced tab. Note, you can also, if required, select explicit acknowledgment and add a confirm activity to the process to ensure the message is not considered delivered until the process has successfully completed.

    We can now also optionally remove the content matcher that was configured for the FTL Subscriber activity in the ReceiveOrderC process, since this is now defined for the durable on the store in the Realm Server. This is more flexible as it allows the matching to be configured administratively rather than statically set in process configuration.

    Now test delivery assurance by first running just the order producer process. After several seconds stop the process and check the store has the messages saved using the Realm Server UI. Click on ?Services? at the top of the page, then select ?Stores?, then select our OrderStore. You should see messages saved for each of the durables as shown below.

    rs-durables.thumb.jpg.8903b1c8941eaf5970b660911a2cc36e.jpg

     

    Now return the BusinessWorks designer studio and run the receiver processes, verify all the pending messages are received.

     

    Attachments

    Download attachments from resources

     

    ftl-orderhandlerconfig.json_.zip

    bw6-orderhandlerproject.zip

    ftl-orderhandlerconfig-persistent.json_.zip

    bw6-orderhandlerproject-persistent.zip


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...