sid
sid

Reputation: 11

Unable to subscribe to topic in KURA

I am writing sample Kura application in Java. But i am not able to receive message on subscribing to the topic .

In Kura web-UI: LWT.topic attribute is :

$EDC/#account-name/#client-id (Eg: acc-name = "acc" client-id="client1")

I am publishing from client using topic $EDC/acc/client1

But i am not receiving the message from the topic i.e following methods will never called onControlMessageArrived() onMessageArrived()

But only there is a message on Kura.log as message arrived on topic $EDC/acc/client1 but not entering into methods onControlMessageArrived() onMessageArrived()

Code snippet:

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

    }


}

Upvotes: 0

Views: 108

Answers (0)

Related Questions