Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 4 Channels and Destinations : Communicating with Other Sources using TCP

Communicating with Other Sources using TCP
In addition to Channels, TIBCO BusinessEvents can also communicate with other data sources using TCP. You can create a local TCP server and a TCP client so that TIBCO BusinessEvents can communicate with data sources not otherwise available through channels, using TCP.
TCP communication is available as a Communication Built-in Function in the Catalog Functions view. Using this set of functions you do the following to communicate with TCP servers:
TCP.connectToRemoteServer()
Register the session listener using TCP.registerSessionListener()
Start the local server using TCP.startLocalServer()
TCP.readIntoPayload(SessionName)
Example TCP Rule Function to Start a Local TCP Server
Here is a sample rule function to start a local TCP server:

 
void rulefunction RuleFunctions.InitTCPServers {
   attribute {
      validity = ACTION;
   }
   scope {
 
   }
   body {
      System.debugOut( "Initializing TCP servers" ) ;
      try {
         TCP.createLocalServer("MyTCPServer", "localhost",             System.getGlobalVariableAsInt("NSN/SocketAdaptor/Port", 8055));
            TCP.registerSessionListener("MyTCPServer",             "/RuleFunctions/RawCDRCallback");
         TCP.startLocalServer("MyTCPServer");
         } catch (Exception ex) {
            System.debugOut("Exception occurred while initializing TCP server: " +
               ex@message);
         }
         System.debugOut("TCP server initialization done");
      }
   }

 
Example TCP Rule Function to Connect to a Remote TCP Server
Here is a sample rule function to connect to a remote TCP server as a client:

 
Events.RemoteMsgResponseEvent rulefunction RuleFunctions.RemoteTCPSender {
   attribute {
      validity = ACTION;
   }
   scope {
      String host;
      int port;
      String message;
   }
   body {
      String tcpNickName = "TCP-" + host + "-" + port + "-"
         + uri + "-" + closure + "-" + System.nanoTime();
      Events.RemoteMsgRequestEvent requestEvent =
         Events.RemoteMsgRequestEvent.RemoteMsgRequestEvent(null, message);
      TCP.connectToRemoteServer(tcpNickName, host, port);
      TCP.write(tcpNickName, requestEvent);
      TCP.endWrite(tcpNickName);
      Events.RemoteMsgResponseEvent responseEvent =
         TCP.readIntoPayloadFully(tcpNickName,
         "/Events/RemoteMsgResponseEvent");
      TCP.disconnectFromRemoteServer(tcpNickName);
      return responseEvent;
   }
}

 
APIs for TCP Communication
The Catalog Functions view lists the following functions (APIs) for TCP communication:
Documentation for functions is provided in the tooltips you can see when browsing the functions in TIBCO BusinessEvents Studio. You can also see this documentation in the TIBCO BusinessEvents Functions Reference, available in the HTML product documentation.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved