Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » MQTT Request/Response in camel
MQTT Request/Response in camel [message #1801303] Wed, 16 January 2019 11:27 Go to next message
Aistis Kaikaris is currently offline Aistis KaikarisFriend
Messages: 33
Registered: March 2018
Member
Hello

I'm having trouble receiving mqtt responses when i send mqtt queries via camel+kura cloud. I was reading:

https://eclipse.github.io/kura/ref/mqtt-namespace.html#mqtt-requestresponse-example

So i wrote a routebuilder to try it out:

public class CommunicationRoute extends RouteBuilder{
	private PayLoadConstructor payloadConstructor;
	
	public CommunicationRoute() {
		this.payloadConstructor = new PayLoadConstructor();
	}

	@Override
	public void configure() throws Exception {
		from("timer://heartbeat?fixedRate=true&period=10000").id("send_route")
		.process(this.payloadConstructor)
		.to("cloud:$EDC/test-gateway/CONF-V1/GET/configurations");

		from("cloud:$EDC/test-gateway/CONF-V1/REPLY/7777").id("receive_route")
		.log("${headers}")
		.log("${body}");

	}

}


And here is the payload builder:

public class PayLoadConstructor implements Processor{

	public void process(Exchange exchange) throws Exception {
		final KuraPayload kuraPayload = new KuraPayload();
		kuraPayload.setTimestamp(new Date());
		kuraPayload.addMetric("request.id", "7777");
		kuraPayload.addMetric("requester.client.id", "DemoEclipseLampNode");
		exchange.getIn().setBody(kuraPayload);
	}
}


The message is sent out, but i don't seem to receive any response, even though the other kura instance is running and is connected to the kapua server. The account name and client id is correct.

As i understand CONF-V1 is a kura service that receives these messages and sends a response? What could be missing here?
Re: MQTT Request/Response in camel [message #1801304 is a reply to message #1801303] Wed, 16 January 2019 11:28 Go to previous messageGo to next message
Matteo Maiero is currently offline Matteo MaieroFriend
Messages: 423
Registered: July 2015
Location: Italy
Senior Member
Are you using control topics?

Best regards,
Matteo
Re: MQTT Request/Response in camel [message #1801308 is a reply to message #1801304] Wed, 16 January 2019 13:30 Go to previous messageGo to next message
Aistis Kaikaris is currently offline Aistis KaikarisFriend
Messages: 33
Registered: March 2018
Member
Matteo Maiero wrote on Wed, 16 January 2019 13:28
Are you using control topics


Hi,

I'm not really sure, the page in question does not seem to mention what control topics are, so i assumed that the example in the kura page:
$EDC/guest/F0:DE:F1:C4:53:DB/CONF-V1/GET/configurations

is a control topic. I thought that 'CONF-V1' was a kura service that listens for the 'configurations' topic. Is this just a mock example and not a real service which listens to the 'configurations' topic?

I also forgot to add the account name, so i changed the topic from:
$EDC/test-gateway/CONF-V1/GET/configurations

to
"$EDC/Lamps/test-gateway/CONF-V1/GET/configurations"


But this still does not get any response.

[Updated on: Wed, 16 January 2019 13:35]

Report message to a moderator

Re: MQTT Request/Response in camel [message #1801335 is a reply to message #1801308] Thu, 17 January 2019 05:44 Go to previous messageGo to next message
Aistis Kaikaris is currently offline Aistis KaikarisFriend
Messages: 33
Registered: March 2018
Member
So a few additional observations.

1) I tried using https://github.com/amitjoy/Kura-MQTT-Client-Utility to publish with the same topic and subscribe to the same topic as my original post and it worked.

2) When i send the message with camel, it gets stored in kapua data and does not seem to reach the kura device (at least i can't see it in the kura log)

3) The topic i write into the camel route gets appended by the camel cloud component with additional information.
So in route i write:
$EDC/Lamps/test-gateway/CONF-V1/GET/configurations

Which then i sent as:
Lamps/DemoEclipseLampNode/$EDC/Lamps/test-gateway/CONF-V1/GET/configurations


So it appends my eclipse instance (which i'm sending the message from) client id and account on top of the message that i write. Is this how it is supposed to work?

[Updated on: Thu, 17 January 2019 06:41]

Report message to a moderator

Re: MQTT Request/Response in camel [message #1801340 is a reply to message #1801335] Thu, 17 January 2019 08:52 Go to previous messageGo to next message
Aistis Kaikaris is currently offline Aistis KaikarisFriend
Messages: 33
Registered: March 2018
Member
UPDATE:

I might have figured out the problem. Still need to do some testing, but i got a 200 response. The problem is that the camel component searches for client_id and other headers, and if it does not find them, it appends them, so i did:

My routbuilder:

public class CommunicationRoute extends RouteBuilder{
	private PayLoadConstructor payloadConstructor;
	
	public CommunicationRoute() {
		this.veryGood= new VeryGood();
		this.payloadConstructor = new PayLoadConstructor();
	}

	@Override
	public void configure() throws Exception {
		from("timer://heartbeat?fixedRate=true&period=100000").id("send_route")
		.process(this.payloadConstructor)
		.log("${headers}")
		.to("kura-cloud:CONF-V1/GET/configurations");

		from("kura-cloud:CONF-V1/REPLY/REQUEST_7RRBNIBVB0045TPM20VRQB1TNH").id("recieve_route")
		.log("${headers}")
		.log("${body}");

	}

}


My PayloadBuilder:
public class PayLoadConstructor implements Processor{

	public void process(Exchange exchange) throws Exception {
		final KuraPayload kuraPayload = new KuraPayload();
		kuraPayload.setTimestamp(new Date());
		exchange.getIn().setHeader(KuraCloudClientConstants.CAMEL_KURA_CLOUD_CONTROL, true);
		exchange.getIn().setHeader(KuraCloudClientConstants.CAMEL_KURA_CLOUD_DEVICEID, "test-gateway");
		kuraPayload.addMetric("request.id", "REQUEST_7RRBNIBVB0045TPM20VRQB1TNH");
		kuraPayload.addMetric("requester.client.id", "DemoEclipseLampNode");
		exchange.getIn().setBody(kuraPayload);
	}
}


Now it appends the headers that i put inside the exchange. 'KuraCloudClientConstants.CAMEL_KURA_CLOUD_CONTROL' appends $EDC, 'KuraCloudClientConstants.CAMEL_KURA_CLOUD_DEVICEID' appends the smartnode i'm sending this message to. Now the topic gets created correctly. This is the source code which appends the headers to the topic:

https://github.com/rhiot/rhiot/blob/82eac10e365f72bab9248b8c3bd0ec9a2fc0a721/gateway/components/camel-kura/src/main/java/io/rhiot/component/kura/cloud/KuraCloudProducer.java

[Updated on: Thu, 17 January 2019 08:57]

Report message to a moderator

Re: MQTT Request/Response in camel [message #1801351 is a reply to message #1801340] Thu, 17 January 2019 11:09 Go to previous messageGo to next message
Pierantonio Merlino is currently offline Pierantonio MerlinoFriend
Messages: 39
Registered: March 2016
Member
Hi,

I try to understand what is your use-case, but there are some details missing...
Could you please explain what you're trying to achieve?

Best,
Pier
Re: MQTT Request/Response in camel [message #1801363 is a reply to message #1801351] Thu, 17 January 2019 13:33 Go to previous message
Aistis Kaikaris is currently offline Aistis KaikarisFriend
Messages: 33
Registered: March 2018
Member
Pierantonio Merlino wrote on Thu, 17 January 2019 13:09
Hi,

I try to understand what is your use-case, but there are some details missing...
Could you please explain what you're trying to achieve?

Best,
Pier


Hi

I was trying to familiarize myself with mqtt kura cloud communication.

I have two test kura devices and one kapua instance running.
First kura device has a camel mqtt publisher and subscriber routes.
First kura device sends an CONF-1 (or one of the examples in the kura webpage) mqtt request via camel route to the second device.

I was trying to get a response with the subscriber, which i eventually got when i made the changes in my former post. After the changes i get reponse header '200' and a body.

Now i'm trying to figure out how to decode the response body, which from what i understand is encoded with google protobuf.

[Updated on: Thu, 17 January 2019 13:34]

Report message to a moderator

Previous Topic:Modbus TCP Problems with string reading
Next Topic:Create new database connection type
Goto Forum:
  


Current Time: Fri Apr 26 00:53:37 GMT 2024

Powered by FUDForum. Page generated in 0.04671 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top