Search Results

TIBCO eFTL C# Quick Start


Getting Started

This quick start guide provides basic instructions for writing TIBCO eFTL applications in C# for TIBCO Cloud Messaging.

Building and running samples

Follow the steps below to build and run the C# samples:

  • Unzip
  • Copy a tcm-config.yaml configuration file into the current working directory.
  • Run sample: dotnet run --project eftl-dotnet-samples/eftlconsumer
  • Run sample: dotnet run --project eftl-dotnet-samples/eftlproducer

Description of sample applications


The producer demonstrates connecting an eFTL C# application to Cloud Messaging and publishing eFTL messages.


The consumer demonstrates connecting an eFTL C# application to Cloud Messaging, creating a subscription, and receiving eFTL messages.

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

Using the eFTL SDK

For C# programs, include the eFTL client C# library: using TIBCO.EFTL;

Connecting to TIBCO Cloud Messaging

The client configuration file contains all the information client applications need to securely connect to TIBCO Cloud Messaging. Generate the client configuration file using the roles REST API or user interface. Generate as many configuration files as needed for each Role.

Note: TIBCO Cloud Messaging samples require a client configuration file to run.

Client Identifiers

You must provide a unique identifier for your client if you want it to receive any messages missed while disconnected. Only one application can connect with a given client id at any given time. If a second application connects with a client id already in use by another application, the first application will disconnect.

Connection Example

Hashtable props = new Hashtable();

// Set the password to tcm_authentication_key
props.Add(EFTL.PROPERTY_PASSWORD, "<tcm_authentication_key>");

// Provide a unique client identifier
props.Add(EFTL.PROPERTY_CLIENT_ID, "abc123");

// Connect to TIBCO Cloud Messaging using the eftl_url
             new ConnectionListener());

class ConnectionListener : IConnectionListener {
   public void OnConnect(IConnection connection){
   public void OnDisconnect(IConnection connection, int code, String reason) {
      Console.WriteLine("disconnected: {0}", reason);
   public void OnReconnect(IConnection connection) {
   public void OnError(IConnection connection, int code, String reason) {
      Console.WriteLine("error: {0}", reason);

OnConnect callback

The onConnect callback is invoked after 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.

Publishing Messages

After the clients are connected to TIBCO Cloud Messaging, they can publish messages. 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.
IMessage message = connection.CreateMessage();
message.SetString("event", "hello");
message.SetString("text": "Hello, World!");

// Publish a message to TIBCO Cloud Messaging
connection.Publish(message, null);

// Publish a message to TIBCO Cloud Messaging
connection.publish(message, new CompletionListener());

// To be notified if the publish was successful or if an error occurred, callbacks can be provided.
CompletionListener : ICompletionListener {
   public void OnCompletion(IMessage message) {
     Console.WriteLine("publish success\n");
   public void OnError(IMessage message, int code, String reason) {
      Console.WriteLine("publish error: {0}", reason);

Receiving Messages

After the clients are connected to TIBCO Cloud Messaging, they can create one or more subscriptions to receive messages of interest. You can subscribe to messages by matching the message fields of 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());

Class SubscriptionListener : ISubscriptionListener {
   public void OnMessage(IMessage[] messages){
      Console.WriteLine("message received: {0}", message.GetString("text"));
   public void OnSubscribe(String subscription) {
   public void OnError(String subscription, int code, String reason) {
      Console.WriteLine("subscription error: {0}", 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.