Apama Capital Markets Foundation Documentation : Capital Markets Foundation : Market Data Management : Market data subscribers : Setting subscription callbacks : Sample code for setting subscription callback
Sample code for setting subscription callback
The following example creates a trade subscriber and then adds a subscription callback. It also shows how to get a connection key object so that you can filter on the com.apama.md.T events that are specific to your subscription. When using a connection key consider the following:
*sessionId filters all subscriptions on the specified session.
*symbol filters all subscriptions across all sessions for the specified symbol.
*connectionId filters for a specific session and symbol subscription, and it is not necessary to additionally specify sessionId or symbol when using connectionId.
*It is possible to subscribe multiple times in different application locations to the same symbol on the same underlying session and using the exact same parameters. Such duplicate subscriptions are treated as the same subscription. They all share the same underlying subscription request, with only a single update being sent for all instances of the duplicate subscriptions. If you subscribe to a symbol in the same way on the same underlying session in multiple places, they all use the same connectionId.
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.md.TradeSubscriberFactory;
using com.apama.md.TradeSubscriber;
 
monitor SubscriberExample10 {
 
context mainContext := context.current();
 
action onload() {
// Create and connect the session handler.
SessionHandler sessionHandler := (new SessionHandlerFactory).
connect(mainContext, "MySession", "MyTransport");
 
// Create the trade subscriber factory and specify the session
// handler plus a symbol to subscribe.
TradeSubscriber subscriber := (new TradeSubscriberFactory).
create(sessionHandler);
integer refId := subscriber.addSubscribedCallback( onSubscribed );
subscriber.subscribe("SOW");
}
 
action onSubscribed( TradeSubscriber subscriber,
com.apama.md.adapter.ConnectionKey connKey ) {
 
// The ConnectionId is a unique identifier for the
// subscribed symbol for the connected session.

on all com.apama.md.T(
connectionId=connKey.getConnectionId() ) {
// Process the trade
}
}
}
Copyright © 2013-2017 Software AG, Darmstadt, Germany. (Innovation Release)

Product LogoContact Support   |   Community   |   Feedback