Jump to content
We have recently updated our Privacy Statement, available here ×
  • Deploying and Developing application with TIBCO Cloud? Messaging, TIBCO Cloud? Integration and TIBCO BusinessWorks? Container Edition


    Manoj Chaurasia

    Table of Contents

    This article walks through an example using TIBCO Cloud? Messaging, TIBCO Cloud? Integration, and TIBCO BusinessWorks? Container Edition together to create a basic pub/sub app.  Knowledge about TIBCO Cloud Integration and TIBCO BusinessWorks Container Edition will be helpful.

    Getting Started:

    There are a few things we need to do before we can develop our applications. The first is making sure that we have all the necessary components. You can receive a free trial of TIBCO Cloud Messaging and TIBCO Cloud Integration from cloud.tibco.com so sign up for those. Also, make sure you have the TIBCO BusinessWorks Container Edition studio available. Your TIBCO Cloud Messaging trial broker may take a little while to be active. Make sure the status says active before starting.

     

    Screenshot2022-11-14at11_24_37AM.png.ac9fdbb530a7e08e053b6496e95e41af.png

    Generate key (Under Authentication Keys), we will be using this key to connect with TIBCO Cloud Messaging. Now, under Download SDK's, download the Java/Android SDK. Unzip the file and under the lib folder, there's a jar file called 'tibeftl.jar'. We will be using this later.

    Development - TIBCO BusinessWorks Container Edition:

    Let's start by opening up our TIBCO BusinessWorks Container Edition studio. Create a new BusinessWorks application, you can call it whatever you want, but in this example, i will call it 'tcm.publish'. Next, let's convert our project to a Java project. Right-click on the .module project. Navigate down to 'Configure' and select 'Convert to Java Project'.

     

    Screenshot2022-11-14at11_24_51AM.png.39857e358e9be8a1ba2905a296058094.png

    Once converted you should see a folder/library under the .module project called 'JRE System Library [TIBCO JRE]'. Right-click on it and navigate down to properties. This will cause a window to pop up where you can select your JRE System Library. Change the Execution environment to J2Se-1.5 (TIBCO JRE) and hit OK.

     

    Screenshot2022-11-14at11_25_02AM.png.84cc4fbe694881fff704d7b7f3aedf84.png

    Now, under your .module project, right-click on the lib folder. Navigate to import->import, this will open up a window prompting you to import certain files. In this case, we will import a 'File System', so let's select that. A new window will pop up that will let you import a file system from a local directory. Select the directory that has your TIBCO Cloud Messaging client that you downloaded earlier (eftl-3.3.2-java). Within that directory, find the tibeftl.jar file (should be in the lib folder). Select that file. Once done, hit finish.

     

    Screenshot2022-11-14at11_25_18AM.png.896b85bab7768b5ff2b339cd79567836.png

    Now under your .module project, expand the Module Descriptors. You will see a descriptor called 'Dependencies', double click it. This will open a new window that will let you add packages to your project. Click on add and a window should pop up for 'Package Selection'. Type in 'com.tibco.bw.palette.sh' and select the palette that appears. Click OK and save your project should now have that jar file under your 'Plug-in Dependencies'.

    Let's create our REST service. Click on the little globe with a cloud on the left-hand side of your screen. This will open up your REST service wizard. Give your Resource a name, I choose 'tcmpublish' and set the Resource Service Path to '/tcmpublish/{text}' (don't include the quotes). Change the operation from POST to GET (only GET should be selected). Once done, hit Finish. Your REST service will now be generated, we will need to configure it more but for now, let's leave it be. Now let's drag and drop the JavaInvoke activity. This will be found within your palette library. Your project should now look something like this.

     

    Screenshot2022-11-14at11_25_29AM.png.4b9c6fa6b178c3012136f2c61b57cd0b.png

    Click on your JavaInvoke activity, you should see the properties for the activity. Under the general tab within the properties tab, you should see a variable called 'Java Global Instance', click on the magnifying glass on the other side of it. This will bring up a new window to create a Java Global Resource. Create the resource. You should now see your 'Java Global Instance' variable filled with your Global Resource. Save your project.

    Now, under your .module project, find the src folder, right-click it and select new -> package. This will bring up a window to create a new java package. In this example I called it 'com.tibco.bw.palette.tcm'.

     

     

    Screenshot2022-11-14at11_25_39AM.png.69a3bf0c8e74b3a93f9154d516aefd7f.png

    Let's go back to our 'Java Invoke' activity properties. Under the general tab (the same place you created the Java Global Instance), create a new class. This is done by clicking on the green C within the 'Class Name' parameter. This will cause a new window to pop up where you will configure your Java class. We need to fill out the Package (should be the name of the Java Package you just created) and the Name (can be anything) value. Once done, hit finish. Example in the screenshot below.

     

    Screenshot2022-11-14at11_25_51AM.png.f8c4a7f58c36174a502c9d84d7f2376b.png

    Now under the src folder, you should see your class created. Double-click on your .java file. This will open it up within the studio, it should be relatively empty, only showing the package name and class.  Now let's edit this file so that we can use it.  Assuming you have followed the guide step by step (with the same names), you can just copy and paste this:

     package com.tibco.bw.palette.tcm;  import java.util.HashMap; import java.util.Properties;  import com.tibco.eftl.Connection; import com.tibco.eftl.ConnectionListener; import com.tibco.eftl.EFTL; import com.tibco.eftl.Message;  public class TCMConnection { 	HashMap<String,Object> moduleProperties = new HashMap<String, Object>(); 	Properties tcmProps = new Properties(); 	 	private String authKey = "";        //TCM authKey 	private String clientId = "";       //TCM clientId (this can be anything) 	private String url = "";            //TCM connection URL 	private Connection tcmConnection; 	 	public TCMConnection() { 		final Properties props = new Properties();  		// set the password using your authentication key 		props.setProperty(EFTL.PROPERTY_PASSWORD, 		              authKey); 		// provide a unique client identifier 		props.setProperty(EFTL.PROPERTY_CLIENT_ID, clientId);  		// connect to TIBCO Cloud Messaging 		EFTL.connect(url, props, new ConnectionListener() { 			public void onConnect(Connection connection) { 				if (connection != null) { 					tcmConnection = connection; 				} 				System.out.printf("connected\n"); 			} 		    public void onDisconnect(Connection connection, int code, String reason) { 		        System.out.printf("disconnected: %s\n", reason); 		    } 		    public void onReconnect(Connection connection) { 		        System.out.printf("reconnected\n"); 		    } 		    public void onError(Connection connection, int code, String reason) { 		        System.out.printf("error: %s\n", reason); 		    } 		}); 		 	} 	 	public String getAuthKey() { 		return authKey; 	} 	 	public String getClientId() { 		return clientId; 	} 	 	public String getUrl() { 		return url; 	} 	 	public Connection getTCMConnection() { 		return tcmConnection; 	} 	 	public void sendMessage(String event, String text) { 		final Message message = tcmConnection.createMessage(); 		message.setString("event", event); 		message.setString("text", text); 		tcmConnection.publish(message, null); 	} }

     

    We need to edit the following variables in the code: authKey, clientId, and url.  The authKey and url come from your TCM authentication keys, while the clientId can be anything as long as it's unique.

    Now, back under the .module application, find the resources folder, expand it and click on the Java Global resource. A new tab/window should open up that will let you configure the instance.  Next to the class variable on that window, click on browse.

     

    Screenshot2022-11-14at11_26_14AM.png.3b3e7d507445fee9b3bfa6da6a3e65ed.png

    A new window would have popped up. Search for the class you created, if you named everything the same as this guide, you can search 'com.t' and it should pop up. Select it and hit finish, you should now see your class parameter filled. Now select the Method (you should only have one choice). Once done, save your project.

    Navigate back to your Java Invoke properties. Under the general tab (where you configured the Java Global Instance), you'll want to hit the reload button on the same line as the Class Name variable. Once reloaded, you should have the Class Name variable filled with something like 'com.tibco.bw...' and under the Method drop-down menu, you should be able to select the sendMessage method.

     

    Screenshot2022-11-14at11_26_43AM.png.7b4b985b7bb1090ac7db37fa1c7334ed.png

    Let's now configure the input. Go to the input tab within the Java Invoke activity. We need to map two parameters, event, and text. For the event we can type the value as 'lambdainvoke'; for text, we will drag and drop the 'text' data source from the GET invoke text parameter. Save your project. Example below. 

     

    Screenshot2022-11-14at11_26_51AM.png.8dce1e9bbd1896fe75d873550b3ea817.png

    You should no longer have an error message for your java invoke activity. Let's finish this up by mapping the input for the REST service. Click on your Reply activity on your design canvas and within the properties go to the input tab. Here we will need to map the response item, for the sake of simplicity you can just copy the following input (as long as you followed along): concat("Published message: ", $get/parameters/tns1:tcmpublishGetParameters/tns1:text, " to topic called demotopic")

     

    Screenshot2022-11-14at11_27_01AM.png.037925546ae4d7db390a0c2f495ad1ca.png

    Let's configure our http connection now. Go to the Resources folder within the .module project and click on the http connection resource. Change the port property from a literal value to a module property. You should now see the port value replaced with the 'BW.CLOUD.PORT'. Save your project. The design portion of the project is done.

    Deployment - BusinessWorks Container Edition

    So now that we've built our BWCE app, we need to deploy it. There's a large number of options for what platform you can deploy it on. If you don't have any PaaS setup, i would recommend just using Docker as it's easy to install and run on your computer. This app deployment is just like any other BWCE application deployment so I won't spend much time explaining this, if you need more information check out some of the videos I've posted on youtube.  

    Flow for docker: Have base BWCE image -> Export EAR -> Create Dockerfile -> docker build (builds image) -> docker run

    If deployed correctly, you should see your project running on port 8080. You can test the REST service by entering some value for the text parameter and you should get a response message with a 200 response code.

    Development - TIBCO Cloud Integration

    Go to cloud.tibco.com and open TIBCO Cloud Integration (TCI) and navigate to the connections tab. We need to make a connection for our TCM instance. Click on 'Add Connection' this will pop up a window for a TIBCO Cloud Messaging Connector. We need to provide a value for the Connection Name (can be anything), Connection URL (the url of your TCM instance), and Authentication Key (the authentication key you created at the start and used in your BWCE project). Once these have been filled in, you can hit save. You should now be able to connect to your TCM instance.

    Now let's start building our TCI app!

    Create a new TCI app, this is done by clicking the 'Create' button. A pop-up will appear asking you to fill in a name, let's call this app 'TCM-Application'. Now let's choose to create a Flogo-app, afterwards, click on the option to 'Create a flow'. A window will pop up where you can enter the name of the flow, in this case, let's call it 'TCM Subscriber', and hit next. Afterward, you will have the option of choosing to start your flow as a blank or with a trigger, pick a trigger and select "Message Subscriber", and hit next. Choose the connection (should only be one) and finish. You should now see something like this:

     

    Screenshot2022-11-14at11_27_16AM.png.996b3851604936d06dcb5739f816bdfe.png

    Click on your TCM Subscriber flow. You should see one activity called "MessageSubscriber" that will have one error. Essentially it's telling you that it still needs to be configured. Click on that activity and go to Output Settings and enter the following schema: { "text": "String" }.

     

    Screenshot2022-11-14at11_27_28AM.png.f3bb857bb2b3d13aabeca41fe1204d0e.png

    The subscriber activity should now be configured fully (the error goes away). Now let's add an activity to this flow. Next to the MessageSubscriber you should see a blue box (you may need to move your mouse around), click on it and you will get the choice to add a new activity. Choose the Log Message activity under the general tab. Now let's configure it. Click on the newly created log activity and go to the Input tab. Set the message value to $TriggerData.message.text.

     

    Screenshot2022-11-14at11_27_46AM.png.4bbb86be66653d12dbe86b64b3fa3bf9.png

    Now we can push our app. Try it out, it should take less than a minute. If successful you should see the app that says "running". 

    Now let's test the entire flow. Go back to where your BWCE application was deployed (Docker, different PaaS, etc..) and run a test command in the swagger interface. You should get a 200 response (just like when you tested it the first time). Now let's check the logs of our TCI project. We should see the message that we wrote within the TCI logs. IF you do, then everything was set up correctly and running. 

     

    Screenshot2022-11-14at11_27_56AM.png.0b04b9bff2a28c0699bbd5c716911bff.png

    This is just a simple example of how you could use BWCE, TCM, and TCI together to build a pub/sub project. Obviously, more real-life solutions you could and would do more with it, but this guide gives an idea of how the pieces fit together. And we can do some other cool things with this sample project, maybe wrap the BWCE endpoint within a lambda call using Flogo. The ideas are endless!


    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...