Open vit21ik opened 6 years ago
Actually I did this changes in my forked repository - https://github.com/vit21ik/paho.mqtt.java/commit/7df2eaaf760da97766d3a64049eed4da6f3309da
I could create merge request to develop branch.
Thanks for the pull request, once we merge it would you mind if I ported your changes over to our new MQTTv5 client?
Eclipse Smarthome would use this as well. A near term release including this could help our current mqtt ambitions.
Added custom headers to mqtt v5
Can be closed, can't it?
@jpwsutton Is there a way to consume these changes via gradle?
How do I use this feature? I used the latest dependency in maven-
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
</dependency>
But I do not see an option to set custom headers.
You can build the jar file from the develop branch as mentioned here and add it to your classpath. These changes will be available as part of 1.3.0 which is overdue.
It is now available in version 1.2.1 and you implement it like so:
MqttClient client = new MqttClient("wss://<BROKER_URI>", "MyClient");
MqttConnectOptions connectOptions = new MqttConnectOptions();
Properties properties = new Properties();
properties.setProperty("X-Amz-CustomAuthorizer-Name", <SOME_VALUE>);
properties.setProperty("X-Amz-CustomAuthorizer-Signature", <SOME_VALUE>);
properties.setProperty(<SOME_VALUE>, <SOME_VALUE>);
connectOptions.setCustomWebSocketHeaders(properties);
client.connect(connectOptions);
It is now available in version 1.2.1 and you implement it like so:
MqttClient client = new MqttClient("wss://<BROKER_URI>", "MyClient"); MqttConnectOptions connectOptions = new MqttConnectOptions(); Properties properties = new Properties(); properties.setProperty("X-Amz-CustomAuthorizer-Name", <SOME_VALUE>); properties.setProperty("X-Amz-CustomAuthorizer-Signature", <SOME_VALUE>); properties.setProperty(<SOME_VALUE>, <SOME_VALUE>); connectOptions.setCustomWebSocketHeaders(properties); client.connect(connectOptions);
How can we retrieve the headers on the subscriber side?
When you need connection to MQTT broker using WebSockets, paho client sets default headers:
In some cases required send custom headers, for example if you wanted to connect to AWS Iot broker. https://docs.aws.amazon.com/iot/latest/developerguide/custom-auth.html
It would be great add custom headers support to WebSocket handshake request.
If this is a bug regarding the Android Service, please raise the bug here instead: https://github.com/eclipse/paho.mqtt.android/issues/new