abhimanyu
abhimanyu

Reputation: 894

How to use AMQP python client for ActiveMQ

I used amqp client to connect ActiveMQ broker.

import amqp

USER = "guest"
PASSWORD = "guest"
HOST = 'localhost'
PORT = '5672'

host = HOST + ":" + PORT

conn = amqp.connection.Connection(host=host,userid=USER,password=PASSWORD,login_method='AMQPLAIN',ssl=True)
conn.connect()

Getting error : OSError: Server unexpectedly closed connection

Upvotes: 2

Views: 2825

Answers (2)

Javier
Javier

Reputation: 2776

Pika uses AMQP 0.9 and ActiveMQ uses 1.0. These protocols are incompatible.

Read the very beginning of the Pika docs.

Read the first line in the ActiveMQ AMQP docs.

Upvotes: 1

doedotdev
doedotdev

Reputation: 575

Looks like the connection params default to the proper settings.

Try just

import amqp

USER = "guest"
PASSWORD = "guest"
HOST = '/'
PORT = '5672'

host = HOST + ":" + PORT

conn = amqp.connection.Connection()
conn.connect()
print(conn.is_closing)

If you look at the implementation of Connection() it is

def __init__(self, host='localhost:5672', userid='guest', password='guest',
                 login_method=None, login_response=None, 

...

So it defaults to the correct stuff and runs for me locally using rabbit mq.

Hope this helps!

Upvotes: 0

Related Questions