Search Results

TIBCO eFTL Java Quick Start

Quick Start Contents


This quick start guide is intended to provide basic instructions for writing Java applications for TIBCO eFTL. It focuses on a collection of sample applications included in the TIBCO eFTL Messaging SDK for Java.

Getting Started

  • Download the TIBCO eFTL Messaging SDK for Java. This guide will refer to your eFTL installation location as <eftl>.
  • Obtain a URL and authentication key from your TIBCO Cloud Messaging account.
  • In the sample application source files, replace the placeholders TIBCO-CLOUD-MESSAGING-URL and TIBCO-CLOUD-MESSAGING-KEY with your account URL and authentication key.

Building and running samples

Follow the steps below to build and run the Java samples:

> cd <eftl>/samples/java
> javac -cp <eftl>/lib/tibeftl.jar *.java
> java -cp <eftl>/lib/tibeftl.jar:. Publisher
> java -cp <eftl>/lib/tibeftl.jar:. Subscriber
> java -cp <eftl>/lib/tibeftl.jar:. SharedSubscriber
> java -cp <eftl>/lib/tibeftl.jar:. LastValueSubscriber

Description of sample applications


Basic publisher program that demonstrates the use of publishing eFTL messages.


Basic subscriber program that demonstrates the use of subscribing to eFTL messages.

Run the Subscriber and Publisher at the same time to demonstrate real-time messaging. Stop the Subscriber, run the Publisher, and restart the Subscriber to demonstrate persistence.


Basic subscriber program that demonstrates the use of subscribing to eFTL messages using a shared durable.

Run multiple instances of the SharedSubscriber and one Publisher to demonstrate message load-balancing across a shared durable subscription.


Basic subscriber program that demonstrates the use of subscribing to eFTL messages using a last-value durable.

Start and stop the LastValueSubscriber. Run the Publisher several times. Re-start the LastValueSubscriber to receive only the last published message to demonstrate the use of a last-value durable subscription.

Using the eFTL SDK

For Java programs, include the eFTL Client Java library JAR file tibeftl.jar in your CLASSPATH.

Connect to TIBCO Cloud Messaging

To establish a connection to TIBCO Cloud Messaging, you need the URL and authentication key. Authentication keys can be obtained only from your TIBCO Cloud Messaging account page on the Authentication key tab. The eFTL client uses the URL to connect to the library. The authentication key is the password used by the eFTL client library to authenticate itself.

Client Identifiers

You must also provide a unique identifier for your client so that it can receive any missed messages while disconnected. Note: Client identifiers must be unique; no two clients with the same identifier can be connected simultaneously.

final Properties props = new Properties(); 
// set the password using your authentication key
props.setProperty(EFTL.PROPERTY_PASSWORD, "6ee7639011dd67ac79272a0844c16671"); 

// provide a unique client identifier 
props.setProperty(EFTL.PROPERTY_CLIENT_ID, "abc123"); 

// connect to TIBCO Cloud Messaging
             props, new ConnectionListener() { 
                @ Override 
                public void onConnect(Connection connection) {
                @ Override 
                public void onDisconnect(Connection connection, int code, String reason) {
                    System.out.printf("disconnected: %s\n", reason); 
                public void onReconnect(Connection connection) {
                public void onError(Connection connection, int code, String reason) 
                    System.out.printf("error: %s\n", reason); 

onConnect callback

The onConnect callback is invoked once the connection to TIBCO Cloud Messaging is established. The Connection object passed to the onConnect callback can be used for subscribing to messages and publishing messages.

onDisconnect callback

If the connection cannot be established, or is lost, the onDisconnect callback is invoked.

onReconnect callback

The onReconnect callback is invoked when the client successfully reconnects to TIBCO Cloud Messaging.

onError callback

The onError callback is invoked when TIBCO Cloud Messaging sends an error to the client.

Publish Messages

Clients can publish messages after they are connected to TIBCO Cloud Messaging. To publish messages, use the connection returned in the onConnect callback.

// Create a message
// Fields and arrays of type string, numeric, date, and sub-messages are used in messages.
connection.publish(message, null);
final Message message = connection.createMessage(); 
message.setString("event", "hello");
message.setString("text": "Hello, World!"); 
// To be notified if the publish was successful or if an error occurred, callbacks can be provided.

// Publish a message to TIBCO Cloud Messaging
connection.publish(message, new CompletionListener() { 
   public void onCompletion(Message message) {
      System.out.printf("publish success\n"); 
   public void onError(Message message, int code, String reason) {
      System.out.printf("publish error: %s\n", reason); 

Receive Messages

After clients are connected to TIBCO Cloud Messaging, they can create one or more subscriptions to receive messages of interest. You subscribe to messages by matching on the message fields that are of your interest. Use the connection returned in the onConnect callback to register subscriptions.

// Create a subscription in TIBCO Cloud Messaging 
// This subscription matches all published messages that contain a 
// field named "event" with a value of "hello" 
// This subscription also sets the durable name to "hello" which allows 
// the client to receive messages that were published while disconnected 
connection.subscribe("{\"event\":\"hello\"}", "hello",
    new SubscriptionListener() { 
        public void onMessage(Message[] messages) { 
            for (Message message : messages) {
                System.out.printf("message received: %s", message.getString("text")); 
        public void onSubscribe(String subscription) { 
        public void onError(String subscription, int code, String reason) { 
            System.out.printf("subscription error: %s\n", reason); 

Matcher field

The matcher field specifies the messages that are to be received by matching their content. In this case, the subscription receives all published messages containing a field named “event” whose value is “hello”.

Durable field

The durable field is the unique subscription name used by TIBCO Cloud Messaging to store messages for the client when the client is not connected.

onMessage callback

The onMessage callback is invoked when the content of a published message matches the subscription’s matcher.

onError callback

The onError callback is invoked when an error occurs while registering the subscription, typically because of an invalid matcher or invalid durable.