MQTT Request/Response in camel [message #1801303] |
Wed, 16 January 2019 06:27  |
Eclipse User |
|
|
|
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 #1801340 is a reply to message #1801335] |
Thu, 17 January 2019 03:52   |
Eclipse User |
|
|
|
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 03:57] by Moderator
|
|
|
|
Re: MQTT Request/Response in camel [message #1801363 is a reply to message #1801351] |
Thu, 17 January 2019 08:33  |
Eclipse User |
|
|
|
Pierantonio Merlino wrote on Thu, 17 January 2019 13:09Hi,
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 08:34] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.17791 seconds