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