我正在用Java编写示例Kura应用程序。但是我无法接收订阅该主题的消息。
在Kura web-UI中: LWT.topic属性是:
$ EDC /#account-name /#client-id(例如:acc-name =“acc”client-id =“client1”)
我正在使用主题从客户端发布 $ EDC / ACC /客户端1
但我没有收到该主题的消息,即以下方法永远不会调用 onControlMessageArrived()onMessageArrived()
但只有在Kura.log上有消息,因为消息到达主题$ EDC / acc / client1但未输入方法onControlMessageArrived()onMessageArrived()
代码段:
public class ConfigurableExample implements ConfigurableComponent, CloudClientListener {
private static final Logger s_logger = LoggerFactory.getLogger(ConfigurableExample.class);
private static final String APP_ID = "Sample";
private CloudService m_cloudService;
private CloudClient m_cloudClient;
public void setCloudService(CloudService cloudService) {
s_logger.info("============================setCloudService============================{}" , cloudService!=null);
m_cloudService = cloudService;
}
public void unsetCloudService(CloudService cloudService) {
m_cloudService = null;
}
protected void activate(ComponentContext componentContext) {
s_logger.info("======================activate()===========================");
try {
if(m_cloudService==null)
throw new KuraException(KuraErrorCode.CONFIGURATION_ATTRIBUTE_INVALID);
if(m_cloudClient==null) {
m_cloudClient = m_cloudService.newCloudClient(APP_ID);
m_cloudClient.addCloudClientListener(this);
s_logger.info("===================={}================",m_cloudService.isConnected());
}
}
catch (KuraException e) {
s_logger.info("============================Exception============================ {}" , e.getMessage());
}
}
protected void deactivate(ComponentContext componentContext) {
s_logger.info("Bundle " + APP_ID + " has stopped!");
}
@Override
public void onConnectionEstablished() {
}
@Override
public void onConnectionLost() {
}
@Override
public void onControlMessageArrived(String arg0, String arg1, KuraPayload arg2, int arg3, boolean arg4) {
s_logger.info("++++++++++++++++++++++onControlMessageArrived with Parameters {},{},{},{},{} ++++++++++++++++++++",arg0, arg1,new String(arg2.getBody()),arg3,arg4);
}
@Override
public void onMessageArrived(String arg0, String arg1, KuraPayload arg2, int arg3, boolean arg4) {
s_logger.info("++++++++++++++++++++++onMessageArrived with Parameters {},{},{},{},{} ++++++++++++++++++++",arg0, arg1,new String(arg2.getBody()),arg3,arg4);
}
@Override
public void onMessageConfirmed(int arg0, String arg1) {
// TODO Auto-generated method stub
}
@Override
public void onMessagePublished(int arg0, String arg1) {
// TODO Auto-generated method stub
}
}