Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从python脚本发送回复消息_Python_Activemq - Fatal编程技术网

从python脚本发送回复消息

从python脚本发送回复消息,python,activemq,Python,Activemq,我开发了一个camel应用程序,它能够通过activemq代理与外部系统通信,目前我正在编写一个简短的演示文稿来展示它是如何工作的 为此,我选择python作为外部系统,因为它是免费的、易于安装的,并且在过去的一些jython脚本中有一点暴露。 我想在演示文稿中展示的是,每当我的系统通过某个队列向外部客户机发送消息时,该客户机都会让它进行一些处理,并回复回消息头中指定的“回复到”队列 因此,我稍微修改了一点活动MQ分发版附带的python示例脚本。这是我修改过的脚本: import time i

我开发了一个camel应用程序,它能够通过activemq代理与外部系统通信,目前我正在编写一个简短的演示文稿来展示它是如何工作的

为此,我选择python作为外部系统,因为它是免费的、易于安装的,并且在过去的一些jython脚本中有一点暴露。 我想在演示文稿中展示的是,每当我的系统通过某个队列向外部客户机发送消息时,该客户机都会让它进行一些处理,并回复回消息头中指定的“回复到”队列

因此,我稍微修改了一点活动MQ分发版附带的python示例脚本。这是我修改过的脚本:

import time
import sys
import os
import stomp

user = os.getenv("ACTIVEMQ_USER") or "admin"
password = os.getenv("ACTIVEMQ_PASSWORD") or "password"
host = os.getenv("ACTIVEMQ_HOST") or "localhost"
port = os.getenv("ACTIVEMQ_PORT") or 61613
destination = sys.argv[1]

class MyListener(stomp.ConnectionListener):

  def __init__(self, receiver, sender):
    self.receiver = receiver
    self.sender = sender
    self.count = 0
    self.start = time.time()

  def on_error(self, headers, message):
    print('received an error %s' % message)

  def on_message(self, headers, message):
    if message == "SHUTDOWN":

      diff = time.time() - self.start
      print("Received %s in %f seconds" % (self.count, diff))
      self.receiver.disconnect()
      self.sender.disconnect()
      sys.exit(0)

    else:
      if self.count==0:
        self.start = time.time()

      self.count += 1
      if self.count % 1000 == 0:
         print("Received %s messages." % self.count)

      if 'reply-to' in headers:
        replyTo = headers['reply-to']
        response = '%s Python says: this is very good indeed' % self.count
        self.sender.send(response, destination=replyTo, persistent='false')

sender = stomp.Connection(host_and_ports = [(host, port)])
sender.start()
sender.connect(login=user, passcode=password)

receiver = stomp.Connection(host_and_ports = [(host, port)])
receiver.set_listener('', MyListener(receiver, sender))
receiver.start()
receiver.connect(login=user, passcode=password)
receiver.subscribe(destination=destination, id=1, ack='auto')

print("Waiting for messages...")
while 1: 
  time.sleep(10)
然后我从我的系统内部发出一万条信息。 如果我注释掉发送者部分,我可以在控制台输出中看到python客户端接收我的所有消息。但是,当我试图回复时,我会收到以下错误消息:

TypeError: send() got multiple values for argument 'destination'
更新: 这是我得到的完整堆栈跟踪

Waiting for messages...
Exception in thread Thread-2:
Traceback (most recent call last):
  File "D:\Dev\python\lib\threading.py", line 920, in _bootstrap_inner
    self.run()
  File "D:\Dev\python\lib\threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "D:\Dev\python\lib\site-packages\stomp\transport.py", line 317, in __receiver_loop
    self.process_frame(f, frame)
  File "D:\Dev\python\lib\site-packages\stomp\transport.py", line 166, in process_frame
    self.notify(frame_type, f.headers, f.body)
  File "D:\Dev\python\lib\site-packages\stomp\transport.py", line 227, in notify
    rtn = notify_func(headers, body)
  File "D:/work/cls-message-router/gradle/scripts/listener4.py", line 42, in on_message
    self.sender.send(response, destination=replyTo, persistent='false')
TypeError: send() got multiple values for argument 'destination'
你能指出我在这里做错了什么,我该如何纠正它吗。 我的python知识非常有限,因此非常欢迎您进行一些解释


提前感谢您的投入。

问题在这一行:

self.sender.send(response, destination=replyTo, persistent='false')
一旦我添加了
body=response
,所有的功能都很好。因此,固定的
send
调用如下所示:

self.sender.send(body=response, destination=replyTo, persistent='false')

请将完整的错误回溯添加到您的问题中。