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();
}

Best Answer

  • wasin.w
    wasin.w admin
    Answer ✓

    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.


Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.