stomp.py | Python client library for accessing messaging servers
kandi X-RAY | stomp.py Summary
kandi X-RAY | stomp.py Summary
"stomp.py" is a Python client library for accessing messaging servers (such as ActiveMQ, Artemis or RabbitMQ) using the STOMP protocol _ (versions 1.0 , 1.1 and 1.2 _). It can also be run as a standalone, command-line client for testing. A basic example of using stomp.py can be found here _. More info can be found on GitHub _.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Try to establish a connection
- Check if the current host needs SSL
- Get the SSL params
- Enable keepalive
- Try to connect to the server
- Return True if the current host needs SSL
- Get SSL parameters
- Disconnects the socket
- Join characters together
- Sends a message
- Send a message to destination
- Nack a message
- Disconnect a device
- Begin a transaction
- Event handler
- Join chars together
- Nack an item
- Unsubscribe from a destination
- Show stats
- Receive data from the server
- Subscribe to a destination
- Acknowledge a message
- Establish a connection
- Send file
- Send a frame
- Establish connection
- Process a frame
stomp.py Key Features
stomp.py Examples and Code Snippets
openssl genrsa -out client.key 4096
openssl req -new -out client.csr -key client.key
openssl x509 -req -days 365 -in client.csr -signkey client.key -out client.pem
rm client.csr
keytool -ge
headers = {}
headers['selector'] = "type='test'"
conn = stomp.Connection12([(args.host, args.port)], auto_content_length=False)
conn.start()
conn.connect(login=args.user, passcode=args.password)
conn.send(body=body, headers=headers, destin
POST /api/generate_report
{
"report_id": 1337
}
GET /api/report?id=1337
{
"ready": false
}
GET /api/report?id=1337
{
"ready": true,
"report": "Lorem ipsum..."
}
import sto
Community Discussions
Trending Discussions on stomp.py
QUESTION
I am seeing behavior in our stomp.py 7.0 client (listener only) where after some idle time of not receiving messages the ActiveMQ 5.15.9 broker seems to drop the client (i.e. looking at the ActiveMQ management console shows zero consumers). The odd thing is the on_disconnected
handler of the client never gets called and we have a health check on the client service that checks the connection is_connected()
, however it still returns true.
Based on my understanding/research (please correct if any of this is false) this is due to the broker trying to clean-up resources it perceives as inactive. Also based on my research "heartbeating" can be used to avoid this perception on the broker.
I know how to send the heartbeat header from the client and how to check the response from the server/broker (as far as what it expects) in on_connected
but my question is how do I send the actual heartbeat from the client to the server/broker? Do I need to send a message on the queue I am listening to? If so how do I send a "heartbeat message" and not have to adjust message handling code in my listeners? Do I send it without a body? Also does the broker need to be configured to accept heartbeats? and If it is not configured would declaring and sending them from the client still result in the broker disconnecting the client?
ANSWER
Answered 2022-Feb-18 at 19:54Heart-beating is part of STOMP 1.2 so as long as your client supports STOMP 1.2 you should be able to configure heart-beating when the connection is established. Also, if your broker supports STOMP 1.2 it should accept the heart-beat
header and adjust its behavior accordingly. You shouldn't have to send your own heart-beats. In the absence of any "normal" STOMP frames the client itself should send an EOL as described in the specification.
If your client doesn't support STOMP 1.2 then you should upgrade to a client that does. The STOMP 1.2 spec was released in October 2012, almost a decade ago now so there's been plenty of time to implement support.
QUESTION
We have containerized ActiveMQ Artemis 2.16.0 and deployed it as a K8s deployment for KEDA.
We use STOMP using stomp.py python module. The ACK-mode is set as client-individual
and consumerWindowSize
= 0 on the connection. We are promptly acknowledging the message as soon as we read it.
The problem is, sometimes, the message count in the web console does not become zero even after all the messages are actually consumed and acknowledged. When I browse the queue, I don't see any messages in it. This is causing KEDA to spin up pods unnecessarily. Please refer to the attached screenshots I attached in the JIRA for this issue.
...ANSWER
Answered 2021-Aug-14 at 11:05I fixed the issue in my application code. My requirement was one queue listener should consume only one message and exit gracefully. So, soon after sending ACK for the consumed message, I disconnected the connection, instead of waiting for the sleep duration to disconnect.
Thanks, Justin, for spending time on this.
QUESTION
I would like to remove messages that are scheduled to be delivered to a specific queue but i'm finding the process to be unnecessarily burdensome.
Here I am sending a blank message to a queue with a delay:
...ANSWER
Answered 2021-Jun-08 at 04:00In order to remove specific messages you need to know the ID which you can get via a browse of the scheduled messages. The only other option available is to use the start and stop time options in the remove operations to remove all messages inside a range.
QUESTION
What am I doing wrong here? I'm trying to use Stomp to test some things with Artemis 2.13.0, but when I uses either the command line utility of a Python script, I can't subscribe to a queue, even after I use the utility to publish a message to an address.
Also, if I give it a new queue name, it creates it, but then doesn't pull messages I publish to it. This is confusing. My actual Java app behaves nothing like this -- it's using JMS
I'm connection like this with the utility:
...ANSWER
Answered 2021-May-26 at 03:19I recommend you try the latest release of ActiveMQ Artemis. Since 2.13.0 was released a year ago a handful of STOMP related issues have been fixed specifically ARTEMIS-2817 which looks like your use-case.
It's not clear to me why you're using the fully-qualified-queue-name (FQQN) so I'm inclined to think this is not the right approach, but regardless the issue you're hitting should be fixed in later versions. If you want multiple consumers to share the messages on a single subscription then using FQQN would be a good option there.
Also, if you want to use the topic/
or queue/
prefix to control routing semantics from the broker then you should set the anycastPrefix
and multicastPrefix
appropriately as described in the documentation.
This may be coincidence but ARTEMIS-2817 was originally reported by "BENJAMIN Lee WARRICK" which is surprisingly similar to "BenW" (i.e. your name).
QUESTION
I am writing a python script using the python stomp library to connect and subscribe to an ActiveMQ message queue.
My code is very similar to the examples in the documentation "Dealing with disconnects" with the addition of the timer being placed in a loop for a long running listener.
The listener class is working to receive and process messages. However after a few minutes, the connection gets disconnected and then the listener stops picking up messages.
Problem:
The on_disconnected method is getting called which runs the connect_and_subscribe() method, however it seems the listener stops working after this happens. Perhaps the listener needs to be re-initialized? After the script is run again, the listener is re-created, it starts picking up messages again, but this is not practical to keep running the script again periodically.
Question 1: How can I set this up to re-connect and re-create the listener automatically?
Question 2: Is there a better way to initialize a long-running listener rather than the timeout loop?
...ANSWER
Answered 2021-Jan-25 at 17:08I was able to solve this issue by refactoring the retry attempts loop and the on_error handler. Also, I have installed and configured supervisor in the docker container to run and manage the listener process. That way if the listener program stops it will be automatically restarted by the supervisor process manager.
Updated python stomp listener scriptinit_listener.py
QUESTION
I have an existing flask application (having a bunch of REST apis) which is hosted by Gunicorn. I also have to send and receive messages from AmazonMQ in the same application. I have functions using stomp.py to send/receive messages from AmazonMQ, but I am not sure where to place them, or how should I use them so as to keep existing flow intact
...ANSWER
Answered 2020-Sep-26 at 03:48Hey thanks for help @AKX, I resolved the issue by triggering the whole process of messaging (Creation of connection, subscription to channel etc) by a method call from on_starting(server) method in gunicorn_config.py
QUESTION
I'm using ActiveMQ Artemis messaging system, and I'm testing my setup with STOMP (stomp.py).
I created an "address" on Artemis called Site.SOF.Order.Fulfillment.Submission.ActiveOmni.Topic
, and attached two queues to it:
Site.SOF.Order.Fulfillment.Submission.ActiveOmni.queue
(multicast)Site.SOF.Order.Fulfillment.Submission.ActiveOmni.log.queue
(multicast)
Here are the exported bindings:
...ANSWER
Answered 2020-Mar-11 at 16:25Let me provide some background information first...
The ActiveMQ Artemis address model includes 3 main elements - addresses, queues, and routing types. These are low-level entities which are used to implement all the different semantics for all the different protocols and configurations the broker supports.
STOMP, by contrast, just supports ambiguous "destinations." The STOMP 1.2 specification says this about destinations:
A STOMP server is modelled as a set of destinations to which messages can be sent. The STOMP protocol treats destinations as opaque string and their syntax is server implementation specific. Additionally STOMP does not define what the delivery semantics of destinations should be. The delivery, or “message exchange”, semantics of destinations can vary from server to server and even from destination to destination. This allows servers to be creative with the semantics that they can support with STOMP.
In the core address model messages are sent to addresses and consumed from queues. Addresses and queues are named independently so the names that the core producer and consumer use can be different.
ActiveMQ Artemis supports both point-to-point and pub/sub semantics for STOMP destinations. You can read more about how to configure these semantics in the latest ActiveMQ Artemis STOMP documentation.
In the STOMP point-to-point use-case a message is sent to a destination and consumed from that same destination. The name that both the STOMP producer and consumer use are the same. In order to support these semantics the broker uses a core address and a core anycast queue with the same name.
In the STOMP pub/sub use-case a client creates a subscription on a destination which it can then use to receive messages sent to that destination. The name that both the STOMP subscriber and producer use are the same. In order to support these semantics the broker uses a core address and a core multicast queue with different names. The name of the core queue is generated by the broker automatically. The subscriber can then receive the messages directly from the underlying core subscription queue.
All this stuff is done behind the scenes for STOMP clients, but it's important to understand how STOMP maps to ActiveMQ Artemis' address model so you can configure things appropriately
In your case you've configured an address with 2 multicast queues and you're trying to consume from those queues. This use-case is a mix between point-to-point and pub/sub because you have statically defined queues (i.e. not queues auto-created by the broker in response to a subscriber) but the queues are multicast. These queues are like statically configured durable subscriptions. To access the queues directly you need to use their fully-qualified queue name (i.e. FQQN) from your client. The FQQN follows the pattern of
::
so in your case you'd use either
QUESTION
I am using the Class - PrintingListener
from stomp.py, and it has the method: on_before_message
.
I am not sure why this method is called. I cannot understand the definition. Could someone clarify the use of this method and when it is called?
...ANSWER
Answered 2020-Mar-10 at 15:38According to the stomp.py documentation, the PrintingListener
"just prints all interactions between the client and server." The on_before_message
is one of the methods defined by stomp.py therefore the PrintingListener
invokes it.
The stomp.py API documentation says this about on_before_message
:
Called by the STOMP connection before a message is returned to the client app. Returns a tuple containing the headers and body (so that implementing listeners can pre-process the content).
Parameters:
- headers (dict) – the message headers
- body – the message body
As stated here, on_before_message
is invoked "so that implementing listeners can pre-process the content." If you don't need to pre-process the content of the message (i.e. the headers or the body) then you can ignore this method.
As the name indicates on_before_message
is invoked immediately before on_message
.
QUESTION
The question is when to send the ACK
or NACK
frames to the broker. The STOMP specification says:
ACK is used to acknowledge consumption of a message from a subscription using client or client-individual acknowledgment. Any messages received from such a subscription will not be considered to have been consumed until the message has been acknowledged via an ACK.
"Consumption" would mean for me "after received and processed". So I can imagine two scenarios.
Scenario A after receiving the message:
...ANSWER
Answered 2020-Feb-12 at 09:45As you said, 'Consumption' would mean 'after received and processed', you need to acknowledge the message when you have successfully processed your message without any exceptions. So scenario B will be the apt one.
From the documentation
NACK is the opposite of ACK. It is used to tell the server that the client did not consume the message.
So NACK in this context would mean that you have received the message and did not process it successfully.
Note: If you are maintaining a separate queue for failed messages(ones that cause Exceptions), then you can publish those message to another(dlq queue
in your case) and positively acknowledge(ACK) to the original queue for those failed messages.
QUESTION
I have this stomp client in javascript:
...ANSWER
Answered 2020-Jan-13 at 21:02Your JavaScript based STOMP client will use websockets to connect to the broker since it is restricted by the web browser environment where it runs. Python STOMP clients don't have this restriction and will simply use a standard TCP connection. I'm not aware of any Python STOMP clients which support websockets. I recommend you configure your STOMP broker to accept both websocket and normal TCP STOMP connections.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install stomp.py
You can use stomp.py like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page