question

Upvotes
Accepted
1 0 1 1

Java创建consumer对象,回调onRefreshMsg方法,数据如何落地

Java创建consumer对象,回调onRefreshMsg方法,数据如何落地

这里操作onRefreshMsg回调方法不能注入,使用@Autowired后此接口不会被回调


class AppClient implements OmmConsumerClient
{
  
   public void onRefreshMsg(RefreshMsg refreshMsg, OmmConsumerEvent event)
   {
  
      System.out.println(refreshMsg);
   }
   
   public void onUpdateMsg(UpdateMsg updateMsg, OmmConsumerEvent event) 
   {
  
      System.out.println(updateMsg);
   }

   public void onStatusMsg(StatusMsg statusMsg, OmmConsumerEvent event) 
   {
  
      System.out.println(statusMsg);
   }

   public void onGenericMsg(GenericMsg genericMsg, OmmConsumerEvent consumerEvent){}
   public void onAckMsg(AckMsg ackMsg, OmmConsumerEvent consumerEvent){}
   public void onAllMsg(Msg msg, OmmConsumerEvent consumerEvent){}
}
OmmConsumer consumer = null;
try
{
   AppClient appClient = new AppClient();
   
   OmmConsumerConfig config = EmaFactory.createOmmConsumerConfig();
   
   consumer  = EmaFactory.createOmmConsumer(config.host("localhost:14002").username("user"));
   
   ReqMsg reqMsg = EmaFactory.createReqMsg();
   
   consumer.registerClient(reqMsg.serviceName("DIRECT_FEED").name("IBM.N"), appClient);
   
   Thread.sleep(60000);         // API calls onRefreshMsg(), onUpdateMsg() and onStatusMsg()
} 
catch (InterruptedException | OmmException excp)
{
   System.out.println(excp.getMessage());
}
finally 
{
   if (consumer != null) consumer.uninitialize();
}
#technologyema-apijavaspring
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Upvotes
Accepted
25.1k 57 17 14

Hello @lingjia.jiang

The EMA API is the one that internally sends incoming data as the OMM messages to the registered OmmConsumerClient-based client class via a callback mechanism.

  • onRefreshMsg(): The API sends the Refresh (aka Image) message to this callback method.
  • onUpdateMsg(): The API sends the Update message to this callback method.
  • onStatusMsg(): The API sends the Status message to this callback method.

And so on.

I admit that I do not have the Spring framework knowledge. however, there are some developer resources that might help you use the EMA API with Spring framework as follows:

Hope this helps.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.