emqttd not getting all messages in same topic when subscriber application is down - persistence

Only receiving last retained message when subscriber application restarted.
OS: Windows
EMQ Broker version : 2.3.10
Eclipse paho
When I am publishing 10 messages on same topic, during that time for some reason subscriber application crashed, after sometime sub application restarted, I am getting only last retaining message only and losing all other data which is big problem.
I am putting Retained flag is true , clean session flag as false and Qos as 1 on both pub and sub.
can some one help on this.
Am I missing any configuration or Erlang broker behaves like getting only last retaining message.

First, the MQTT broker will only hold the last message published to a topic with the retained flag for a given topic. Retained messages are not related to the queuing of high QOS messages for offline clients. For more details on retained messages I suggest you look at this post from HiveMQ
As for queuing messages for an offline client you need to meet all of the following points.
The clean session flag must be set to false
The client ID must remain the same across connections
The message must be published with a QOS > 0
The client must subscribe to the topic with a QOS > 0
For more details about persistence and queued messages look at this other HiveMQ post.

Related

Is there a way to control the message output speed of MQTT broker?

I am planning an MQTT project with multiple publishers. MQTT broker receives messages from different publishers. Is there a way to control the message output rate from the MQTT broker? For example, the broker queue forward messages to subscribers at 2 seconds interval. But the broker receives messages all the time.
In such a way, can we control the exit rate from MQTT broker?
No, not really.
It's important to understand that MQTT is pub/sub not really a message queue system.
It is worth remembering that if the subscribing clients can not consume and process messages quicker than they are created then the system will eventually fail, they will have to back up somewhere (most likely in the broker) which will eventually fail due to either memory or storage exhaustion.
Assuming the client is subscribed at QOS 1 or 2 and the broker is configured with only 1 inflight message at a time, then the client should be able to control the rate it handles messages by controlling how it handles the QOS handshake. But this tends to be a bad idea for the reasons already mentioned and not all clients give you any control over the handshake steps.

How to handle application failure after reading event from source in Spring Cloud Stream with rabbit MQ

I am using Spring Cloud Stream over RabbitMQ for my project. I have a processor that reads from a source, process the message and publish it to the sink.
Is my understanding correct that if my application picks up an event from the stream and fails (e.g. app sudden death):
unless I ack the message or
I save the message after reading it from the queue
then my event would be lost? What other option would I have to make sure not to lose the event in such case?
DIgging through the Rabbit-MQ documentation I found this very useful example page for the different types of queues and message deliveries for RabbitMQ, and most of them can be used with AMPQ.
In particular looking at the work queue example for java, I found exactly the answer that I was looking for:
Message acknowledgment
Doing a task can take a few seconds. You may wonder what happens if
one of the consumers starts a long task and dies with it only partly
done. With our current code, once RabbitMQ delivers a message to the
consumer it immediately marks it for deletion. In this case, if you
kill a worker we will lose the message it was just processing. We'll
also lose all the messages that were dispatched to this particular
worker but were not yet handled. But we don't want to lose any tasks.
If a worker dies, we'd like the task to be delivered to another
worker.
In order to make sure a message is never lost, RabbitMQ supports
message acknowledgments. An ack(nowledgement) is sent back by the
consumer to tell RabbitMQ that a particular message has been received,
processed and that RabbitMQ is free to delete it.
If a consumer dies (its channel is closed, connection is closed, or
TCP connection is lost) without sending an ack, RabbitMQ will
understand that a message wasn't processed fully and will re-queue it.
If there are other consumers online at the same time, it will then
quickly redeliver it to another consumer. That way you can be sure
that no message is lost, even if the workers occasionally die.
There aren't any message timeouts; RabbitMQ will redeliver the message
when the consumer dies. It's fine even if processing a message takes a
very, very long time.
Manual message acknowledgments are turned on by default. In previous
examples we explicitly turned them off via the autoAck=true flag. It's
time to set this flag to false and send a proper acknowledgment from
the worker, once we're done with a task.
Thinking about it, using the ACK seems to be the logic thing to do. The reason why I didn't think about it before, is because I thought of a ACK just under the perspective of the publisher and not of the broker. The piece of documentation above was very useful to me.

How can persistent JMS message survive if listener shut down

i have a topic and i post a message to the topic note: I stopped all JMS queue listeners.
Now i restart the server now this time with listeners on, i was expecting the system to consume my previously posted message. But it didn't happen that way.
i have read the documentation of JBOSS - hornetq it says all the JMS messages are persistent in nature.How can i demonstrate that messages are persistent in nature? Messages should have been consumed in the second run; as the message would have been in some persistent database of the messaging queue.
http://activemq.apache.org/what-is-the-difference-between-persistent-and-non-persistent-delivery.html
the document says that it persistent JMS message can survive a broker restart, My question mean can persistent JMS message survive a listener restart, if not how can i acheive it?
I think you're simply experiencing the normal semantics of a JMS topic. Here's a few things to keep in mind:
Any message sent to a topic is placed in the matching subscription(s) on that topic. If there are no matching subscriptions on the topic then the message is discarded.
Topic subscriptions are not durable by default and any messages in a non-durable subscription are discarded when the subscriber disconnects.
In order for messages sent to a topic to survive a broker restart the subscription must be durable and the message must be persistent.

Keeping a series of messages in an MQTT Topic

I'm not sure if this is possible or not. If I set a number of messages to be persisted under a topic for some period of time, can I later grab all of them?
I have an MQTT Broker (Mosquitto) set up already for communication between my services but I now also need some storage for several messages, ideally keeping the last 24 hours worth of messages and being able to pull them out later.
Message persistence is only for clients that have subscribed but are currently disconnected and when they do reconnect do so with the cleanSession flag set to false. In which case all the messages published while that client was disconnected.
You can not use a MQTT broker to store an arbitrary number of messages and retrieve them later. If a client is connected then all messages for it's collection of subscribed topics will be delivered as soon as possible.
Of you want to log messages for later you will have to implement this separately, there are plenty of examples of applications that store messages in databases available

Does Activemq ensure persistence?

I am using activemq queues in my project. Does it guarantee that messages will remain in the queue until dispatched even in the event of failures?
if enabled to do so, yes...it will persist messages in a message store (file, database, etc) and only remove them after they have been successfully dequeued
see this page for details on persistence options: http://activemq.apache.org/persistence.html
see this page for exception handling options: http://activemq.apache.org/message-redelivery-and-dlq-handling.html
In addition to the broker persistence configuration, you need to insure the message producer delivery mode is persistent - see this.
On the consumer side the acknowledgement mode of the session will indicate when the message is acknowledged. Usually the default behavior of the JMS client is AUTO - the message is acknowledged when the receive method returns. But watch out, some wrapper like Spring might send the ACK before! In this case you may want to use Client acknowledgement or transactions...