通过 AWS lambda 中的 python Stomp 库连接 AWSMQ

问题描述 投票:0回答:1

我正在尝试使用Python中的AWS lambda中的Stomp库连接到AWSMQ消息代理。下面是我的代码:

# Imports
from __future__ import print_function
import time
import sys
import stomp    

    def lambda_handler(event, context):
    # TODO implement
    message_to_mq()

    def message_to_mq():
    print ("send message to MQ")
    conn = stomp.Connection()
    conn.set_ssl(for_hosts=[('stomp+ssl://<end point>', <port>)])
    conn.connect('<username>', '<password>', wait=True)
    time.sleep(2)
    conn.disconnect()

但是收到以下错误:

Response:
{
  "errorType": "ConnectFailedException",
  "stackTrace": [
    "  File \"/awsmq.py\", line 10, in lambda_handler\n    message_to_mq()\n",
    "  File \"/awsmq.py\", line 17, in message_to_mq\n    conn.connect('<username>', '<password>', wait=True)\n",
    "  File \"/stomp/connect.py\", line 161, in connect\n    self.transport.start()\n",
    "  File \"/stomp/transport.py\", line 104, in start\n    self.attempt_connection()\n",
    "  File \"/stomp/transport.py\", line 800, in attempt_connection\n    raise exception.ConnectFailedException()\n"
  ]
}

功能日志:

send message to MQ
[WARNING]   Could not connect to host localhost, port 61613
Traceback (most recent call last):
  File "/stomp/transport.py", line 727, in attempt_connection
    self.socket = socket.create_connection(host_and_port, self.__timeout)
  File "/socket.py", line 728, in create_connection
    raise err
  File "/socket.py", line 711, in create_connection
    sock = socket(af, socktype, proto)
  File "/socket.py", line 151, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
    OSError: [Errno 97] Address family not supported by protocol
    [WARNING] Could not connect to host localhost, port 61613
    Traceback (most recent call last):
  File "/stomp/transport.py", line 727, in attempt_connection
    self.socket = socket.create_connection(host_and_port, self.__timeout)
  File "/socket.py", line 728, in create_connection
    raise err
  File "/socket.py", line 711, in create_connection
    sock = socket(af, socktype, proto)
  File "/socket.py", line 151, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
stomp
1个回答
0
投票

如何将 stomp 库添加到 lambda,我尝试使用图层安装它,但无法

© www.soinside.com 2019 - 2024. All rights reserved.