How to get MQTT subscriptions - java

As a MQTT client I want to know how can I get subscriptions(TOPICS):
I use Paho library and java as a client, with connecting with setCleanSession(false) so the client subscriptions(TOPIC) keeps in MQTT broker after disconnecting, if the topic subscription didn't emits some data , I didn't know that subscription is alive.
so I want to get all topic subscriptions of my MQTT client and if some topic didn't emits data for 10 minutes , unsubscribe that topic.

You can not.
There is no way to query the broker for what topics the client has subscribed to in the protocol and in fact most MQTT client libraries don't even keep a list of subscribed topics for the current session.

Related

Azure Service Bus - Subscriptions and DLQ

I have recently started working on Azure Service Bus module which is currently used in our project. The current model is that, we send message to a topic and the topic has multiple subscriptions. There is no filter for subscriptions and the subscribers consume it(Currently not looking to add filters).
Question: Let's say there is 1 topic and 3 subscriptions. The message sent to topic is broadcasted to all subscriptions and applications from two subscriptions consume it. Application for the third subscription goes down and the message is not consumed.
What happens to the message from the 3rd subscription, will it be sent to Dead Letter Queue after TTL
Is there a way to find out, for which subscription the message wasn't consumed
What happens to the message from the 3rd subscription, will it be sent to Dead Letter Queue after TTL
If subscription is configured to dead-letter expired messages, yes, that's what will happen.
Is there a way to find out, for which subscription the message wasn't consumed
You shouldn't do that. Topics and subscriptions are intended to implement Pub/Sub pattern and is about decoupling the senders from the receivers.

Channel vs. Broker vs. Destination in Websocket

What is the difference between channel vs. broker vs. destination in Spring websocket?
I recently started working with a websocket and from what I understood:
registry.addEndpoint("/wsocket/") adds a websocket endpoint which is solely used when clients wants to connect to the websocket service:
this.client.configure({
brokerURL: `ws://localhost:9022/wsocket`,
onConnect: () => {
this.client.subscribe('/quote/fb', message => {
console.log(message);
});
}
});
this.client.activate();
config.enableSimpleBroker("/quote") enables a channel/broker, letting clients to subscribe to it and receive messages published/sent over it. Clients are able to subscribe to any /quote/* on the server.
config.setApplicationDestinationPrefixes("/app") sets the application prefix, which clients use to send message directly to the app and not through the broker.
Is my understanding correct?
I think your understanding is correct .
Broker
A message broker acts as an intermediary platform when it comes to processing communication between two applications. In the context of spring websocket :
When you use Spring’s STOMP support, the Spring WebSocket application acts as the STOMP broker to clients. Messages are routed to #Controller message-handling methods or to a simple in-memory broker that keeps track of subscriptions and broadcasts messages to subscribed users. You can also configure Spring to work with a dedicated STOMP broker (such as RabbitMQ, ActiveMQ, and others) for the actual broadcasting of messages. In that case, Spring maintains TCP connections to the broker, relays messages to it, and passes messages from it down to connected WebSocket clients.
Channel
It can be thought of as a logical segregation of messages in one or both directions. For example, there can be three channels. One for request(incoming to the server), second one for response(outgoing from the server) and third one for error (outgoing from the server).
Destination
It can be thought of another level of hierarchical nesting for a channel. I find this image helpful to understand it :
https://docs.spring.io/spring/docs/5.1.3.BUILD-SNAPSHOT/spring-framework-reference/images/message-flow-simple-broker.png
[![enter image description here][1]][1]
Clients can use the SEND or SUBSCRIBE commands to send or subscribe for messages, along with a destination header that describes what the message is about and who should receive it. This enables a simple publish-subscribe mechanism that you can use to send messages through the broker to other connected clients or to send messages to the server to request that some work be performed.
I find Spring documentation on this topic to be very helpful : https://docs.spring.io/spring/docs/5.1.3.BUILD-SNAPSHOT/spring-framework-reference/web.html#websocket-stomp-handle-simple-broker .

Java Client for MQTT using AWS IoT

I am fairly new to the Aws IoT . I am aware that we can write the Java client for Aws IoT. I have below three queries:
Is the Java Client used only to receive messages from the 'Thing' on Aws ?
Can other devices subscribe to the Java Client
Can this client also send messages to other devices
It will be helpful if you could help out with the starting point to implement the Java. References to any articles or links would really helpful.
Is the Java Client used only to receive messages from the 'Thing' on Aws ?
Let's assume under the Java client we will understand the MQTT client. MQTT is a messaging protocol (most commonly used with AWS IoT - at least what I've seen). And you can consider the AWS IoT as a messaging hub.
So your client can subscribe for messages from things or queues to receive messages, but as well your client could send messages to the topics or things (topics reserved for things). All things or devices are effectively messaging clients for the IoT hub.
Can other devices subscribe to the Java Client
I don't full understand your question. So I'll be guessing that your question is about other clients or devices could receive messages from your application? (a device is just another client).
The clients can subsribe to their tpoic (representing a device or functionality). Your application can send a message (see point 1) to a topic for any device it wants.
Can this client also send messages to other devices
sending messages to other devices means sending messages to topics, to which the other devices are subscribed
help out with the starting point to implement the Java
You may check the Eclipse Paho project (MQTT client)

How to prevent Paho to send an ACK after processing a message from the broker?

I am working on a project with Paho on Java. Messages received from the broker are sent to an API that processes them, but this process might fail or take to long. I would like to take advantage of MQTT acknowledgement system and, in such cases, prevent the ACK to be sent so the broker resends the same message after a while. Is this possible with Paho?
Regards.
There is no way to guarantee that this will work. Message retries are implementation specific.
Section 4.4 of the MQTT v3.1.1 spec states
When a Client reconnects with CleanSession set to 0, both the Client
and Server MUST re-send any unacknowledged PUBLISH Packets (where QoS
0) and PUBREL Packets using their original Packet Identifiers [MQTT-4.4.0-1]. This is the only circumstance where a Client or Server
is REQUIRED to redeliver messages.
The emphasis is mine.
The trend I've seen is for implementations to remove message retries except for when reconnecting.
I facing the same situation, and found it's been a built-in feature of the Java phho mqtt client.
https://github.com/eclipse/paho.mqtt.java/blob/master/org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/IMqttAsyncClient.java#L823
Here is a demo code to show how to use it.
#enable manual ack
client.setManualAcks(true);
#send ack after message processed
client.messageArrivedComplete(messageId, qos);

JMS consumer with ActiveMQ network of brokers

I have a JMS topic on an ActiveMQ network of brokers cluster (aka distributed topic). I have an external JMS consumer (Weblogic portal) that needs to subscribe to this topic and get all the messages sent to it (across all brokers).
If the consumer subscribes to the topic on one of the brokers, it will only get the subset of the messages that the broker receives, correct?
I guess I could create a consumer for each broker and aggregate the messages together, but then I'm also on the hook for dealing with connection issues and needing to know which brokers are available, etc.
Question, is there a way to configure the network of brokers or consumer to get all the messages from a distributed JMS topic?
If the consumer subscribes to the
topic on one of the brokers, it will
only get the subset of the messages
that the broker receives, correct?
Technically, yes, but the broker network is responsible for knowing which consumers are interested in which messages, and making sure that the right brokers get the right messages.
Normally, this means that every broker gets every message, but if a broker only has consumers with a given message selector, it will only get messages that those clients are interested in.
In practise, this means you pick a broker, connect to it, and let the broker network sort it out amongst themselves. In theory.
You just connect to the cluster. It is up to the cluster to deliver the messages to the consumer.

Categories