stomp.py icon indicating copy to clipboard operation
stomp.py copied to clipboard

How to connect to the amazonmq broker like `ssl://b-62f0ce63-0-1.mq.cn-north-1.amazonaws.com.cn:61617`?

Open alterhu2020 opened this issue 2 years ago • 3 comments

For java client we can connect amazonMQ like the following broker failover url:

failover:(ssl://b-62f0ce63-0-1.mq.cn-north-1.amazonaws.com.cn:61617,ssl://b-62f0ce63-0-2.mq.cn-north-1.amazonaws.com.cn:61617)?randomize=true

but when I use with stomp.py like the following code:

    host_and_ports = []
    hosts = ["b-62f0ce63-0-1.mq.cn-north-1.amazonaws.com.cn:61617",
             "b-62f0ce63-0-2.mq.cn-north-1.amazonaws.com.cn:61617"]
    for host in hosts:
        host_and_port = list(host.split(':'))
        host_and_port[1] = int(host_and_port[1])
        host_and_ports.append(tuple(host_and_port))
    con = stomp.Connection(
        host_and_ports=host_and_ports
    )
    listener = TestListener(print_to_log=True)
    con.set_listener('latest_logging', listener)
    con.connect(username='xxx', passcode='xxxxx', with_connect_command=True, wait=True)

It will throw the following errors:

Could not connect to host b-62f0ce63-0-1.mq.cn-north-1.amazonaws.com.cn, port 61617
Unknown response frame type: ';activemq' (frame length was 11)
Unknown response frame type: '' (frame length was 2)
Unknown response frame type: ')' (frame length was 2)
Unknown response frame type: '' (frame length was 1)
Unknown response frame type: 'tcpnodelayenabled' (frame length was 20)
Unknown response frame type: 'sizeprefixdisabled' (frame length was 20)
Unknown response frame type: '	cachesize' (frame length was 11)
Unknown response frame type: '' (frame length was 1)
Unknown response frame type: 'providername	' (frame length was 14)
Unknown response frame type: activemq' (frame length was 9)
Unknown response frame type: 'stacktraceenabled' (frame length was 20)
Unknown response frame type: 'platformdetails	' (frame length was 17)
Unknown response frame type: 'java' (frame length was 5)
Unknown response frame type: 'cacheenabled' (frame length was 15)
Unknown response frame type: 'tightencodingenabled' (frame length was 23)
Unknown response frame type: 'maxframesize' (frame length was 14)
Unknown response frame type: '@' (frame length was 2)
Unknown response frame type: 'maxinactivityduration' (frame length was 23)
Unknown response frame type: 'u0' (frame length was 2)
Unknown response frame type: ' maxinactivitydurationinitaldelay' (frame length was 34)
Unknown response frame type: ''' (frame length was 2)
Unknown response frame type: 'providerversion	' (frame length was 17)
Traceback (most recent call last):
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/peter/try_mq.py", line 22, in <module>
    con.connect(username='xxxx', passcode='xxxxx', with_connect_command=True, wait=True)
  File "/Users/peter/opt/miniconda3/envs/python310/lib/python3.10/site-packages/stomp/connect.py", line 151, in connect
    Protocol11.connect(self, *args, **kwargs)
  File "/Users/peter/opt/miniconda3/envs/python310-latest/lib/python3.10/site-packages/stomp/protocol.py", line 339, in connect
    self.transport.wait_for_connection()
  File "/Users/peter/opt/miniconda3/envs/python310-latest/lib/python3.10/site-packages/stomp/transport.py", line 344, in wait_for_connection
    raise exception.ConnectFailedException()
stomp.exception.ConnectFailedException

any clue for this? thanks for team's help

alterhu2020 avatar Apr 19 '22 13:04 alterhu2020

I don't use amazon, but if you're connecting to ssl URLs with java, you need to connect using ssl with Python. Example here: https://github.com/jasonrbriggs/stomp.py/blob/dev/tests/test_ssl.py

jasonrbriggs avatar Apr 19 '22 18:04 jasonrbriggs

@alterhu2020 Have you tried connecting to amazon active MQ? Are you able to successfully connect?

Dhyanesh97 avatar Apr 25 '22 07:04 Dhyanesh97

Hi @Dhyanesh97 Not yet now. When i search from our server side code found that it can connect as following code:

    @Bean
    public ConnectionFactory connectionFactory() {
        return new ActiveMQConnectionFactory(username, password, brokerUrl);
    }

which only need these arguments:

  • username
  • password
  • brokerUrl

The above document need to use key_file='tmp/client.key', cert_file='tmp/client.pem', ca_certs='tmp/broker2.pem' that's not the correct way I think. Anyone can help for it?

alterhu2020 avatar Jul 10 '22 09:07 alterhu2020