stomper
stomper copied to clipboard
Connection Failed running examples sender.py and receiver.py
Hi,
I'm train to use and understand the lib and i having a problem running the exmaples sender.py and receiver.py
python sender.py Connection failed. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionRefusedError'>: Connection was refused by other side: 10061: No se puede establecer una conexión ya que el equipo de destino denegó expresamente dicha conexión.
python receiver.py Connection failed. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionRefusedError'>: Connection was refused by other side: 10061: No se puede establecer una conexión ya que el equipo de destino denegó expresamente dicha conexión..
I did not make any changes to the code and I get the error. Next i change port, user and pass to somithing else but not work and i have the same error
Can you help me?
thanks
Hi There, I haven't looked at this for quite a while. What broker are you running the examples with?
The examples are broken. Its been a long time since I've run ActiveMQ. To run an activemq broker this time I had a look at https://github.com/rmohr/docker-activemq and then used a docker container to speed things a long:
docker pull rmohr/activemq
docker run --rm -p 61613:61613 -p 8161:8161 -it rmohr/activemq:latest
Now when I run the sender/receiver they break as they are old python2.7 code. I've updated the examples for Python3 locally. Once I tidy the code up a bit, I'll commit and push out a new release.
For anyone else, I'm updating the code base on this branch https://github.com/oisinmulvihill/stomper/tree/feature/fix-examples-for-python3. All examples work there.
Hi Oisin,
This is a great news! Thank you for your prompt reply.
Sincerely, Diego
Oisin,
Can you add some more example details for parsing the msg For example on the dataReceived method for your WebSocket you unpack_frame(data.decode) Here you have the msg with stomp data related to the suscription and the body data related to bussines. For example:
{
'cmd': 'MESSAGE',
'headers': {'destination': '/path/endpoint', 'content-type': 'text/plain;charset=UTF-8', 'subscription': 'subscriptionID', 'message-id': '4444', 'content-length': '337'},
'body':'{"type":"msgType","colorCodesHTML":{"red":"01","black":"02","blue":"03"},"colorCodesCMY":{"red":"03,"black":"02","blue":"03"}}'
}
How can I use the stomper.Engine to parse the msg in a eficient way? for example supouse that you must route the body to proccess A if the subscription key is A and to B if subscription key is B
class MyStomp(stomper.Engine):
def react(self, msg):
pass
def act(self,msg):
pass
def receipt(self, msg):
if msg.getSuscription() == "A"
do stuff A
if msg.getSuscription() == "B"
do stuff B
# form WebSocket
def dataReceived(self, data):
msg = stomper.unpack_frame(data.decode())
returned = self.react(msg)
#print "sender returned: <%s>" % returned
if returned:
self.transport.write(returned.encode())