Alan Coromano
Alan Coromano

Reputation: 26008

How can I receive the missing messages in STOMP?

I have a python script which has to run 24/7 on a linux server and receive ActiveMQ push notification from another server via STOMP. It can happen that the script fails for any reason and will be down for some time, apparently for 30 minutes at most or just a few minutes in average.

I'll need to receive the missing messages-notifications somehow after the script becomes up again if it was down before. As far as I understand, and my understanding is limited, it's possible and the server will send them once my script becomes up. Here's what me believe it to be true

https://activemq.apache.org/apollo/documentation/stomp-manual.html#Topic_Durable_Subscriptions

A durable subscription is a queue which is subscribed to a topic so that even if the client which created the durable subscription is not online, he can still get a copy of all the messages sent to the topic when he comes back online. Multiple clients can subscribe to the same durable subscription and since it's backed by a queue, those subscribers will have the topic's messages load balanced across them.

And in python:

import stomp

# ....
conn.subscribe(destination="/topic/some_topic", id=1, ack="auto", headers={"activemq.subscriptionName": "SampleSubscription"})

Is that what I think it is?

Will my script receive the missing messages once it becomes up again?

Does "id" have always be equal to 1?

update:

Here are the headers I receive at on_message method in Python:

{
'priority': '4', 
'persistent': 'true', 
'message-id': 'fdsfds', 
'expires': '432432432', 
'destination': '/topic/fdsfds', 
'timestamp': '42343243', 
'subscription': '0', 
'type': 'aaaaa'
}

Do "persistent" and, maybe, "subscription", imply that if my client-consumer is offline then once it goes online again it'll be sent all the messages it's missed while it was offline?

Upvotes: 1

Views: 2859

Answers (2)

Maryam Homayouni
Maryam Homayouni

Reputation: 943

No, actually persistent doesn't send the missed messages when server is offline; Persistent messages in activeMQ means that when you restart activeMQ, messages in queue doesn't get lost and they will be kept to be received in future.

And if you want to send a persistent message in activemq using python and stomp, you have to add the following STOMP header to all SEND requests: persistent:true.

And you have to do write it like this:

conn.send('queue name', 'message', headers={'persistent':'true'}) 

Upvotes: 0

mjn
mjn

Reputation: 36644

For Apache ActiveMQ please check the documentation on http://activemq.apache.org/stomp.html. It specifies that the header on the SUBSCRIBE frame must be activemq.subscriptionName.

For ActiveMQ Apollo please check https://activemq.apache.org/apollo/documentation/stomp-manual.html#Topic_Durable_Subscriptions

Upvotes: 2

Related Questions