- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要一些帮助。我在下面有这段代码,日志告诉我我没有传递持久参数,但是正如您所看到的,我正在传递。我已经尝试了一切,并且总是有相同的错误。
要安装此代码,我使用了以下链接:
https://github.com/sk2/ANK-NG/blob/master/rabbitmq/rabbit_websocket.py
https://pika.readthedocs.io/en/0.10.0/examples/tornado_consumer.html
websocket.py:
import pika
import tornado
import tornado.websocket as websocket
from tornado.options import options, define, parse_command_line
import tornado.httpserver
import tornado.ioloop
import tornado.wsgi
from pika.adapters.tornado_connection import TornadoConnection
from witbot import recebeInput
import logging
LOG_FORMAT = ('%(levelname) -10s %(asctime)s %(name) -30s %(funcName) '
'-35s %(lineno) -5d: %(message)s')
LOGGER = logging.getLogger(__name__)
class MyWebSocketHandler(websocket.WebSocketHandler):
def allow_draft76(self):
# for iOS 5.0 Safari
return True
def check_origin(self, origin):
return True
def open(self, *args, **kwargs):
self.application.pc.add_event_listener(self)
print ("WebSocket opened")
def on_close(self):
print ("WebSocket closed")
self.application.pc.remove_event_listener(self)
def on_message(self, message):
print (message)
self.application.pc.send_message(message)
class PikaClient(object):
def __init__(self, io_loop):
print ('PikaClient: __init__')
self.io_loop = io_loop
self.connected = False
self.connecting = False
self.connection = None
self.channel = None
self.event_listeners = set([])
def connect(self):
logging.basicConfig(level=logging.DEBUG)
if self.connecting:
print ('PikaClient: Already connecting to RabbitMQ')
return
print ('PikaClient: Connecting to RabbitMQ')
self.connecting = True
port = 5672
cred = pika.PlainCredentials(username='guest', password='guest')
param = pika.ConnectionParameters(host='192.168.99.100',port=port,credentials=cred,heartbeat_interval=5)
print(param)
self.connection = TornadoConnection(param,
on_open_callback=self.on_connected)
print(self.connection)
self.connection.add_on_close_callback(self.on_closed)
def on_connected(self, connection):
print ('PikaClient: connected to RabbitMQ')
self.connected = True
self.connection = connection
self.connection.channel(self.on_channel_open)
def on_channel_open(self, channel):
print ('PikaClient: Channel open, Declaring exchange')
self.channel = channel
self.setup_exchange('amq.topic')
def setup_exchange(self, exchange_name):
print('Declaring exchange %s', exchange_name)
self.channel.exchange_declare(self.on_exchange_declareok, exchange=exchange_name,exchange_type='topic',durable=True)
def on_exchange_declareok(self, unused_frame):
print('Exchange declared')
self.setup_queue('bot.commands')
def setup_queue(self, queue_name):
print('Declaring queue %s', queue_name)
self.channel.queue_declare(self.on_queue_declareok, queue_name)
def on_queue_declareok(self, method_frame):
print ('Binding %s to %s with %s', 'amq.topic', 'bot.commands', 'bot.commands')
self.channel.queue_bind(self.on_bindok, 'bot.commands',
'amq.topic', 'bot.commands')
def on_bindok(self, unused_frame):
print('Queue bound')
self.start_consuming()
def start_consuming(self):
print('Issuing consumer related RPC commands')
self._consumer_tag = self.channel.basic_consume(self.on_message,'bot.commands')
def on_closed(self, connection):
print ('PikaClient: rabbit connection closed')
self.io_loop.stop()
def on_message(self, channel, method, header, body):
print ('PikaClient: message received: %s' % body)
self.notify_listeners(body)
def send_message(self, body):
self.channel.basic_publish(exchange='topic',
routing_key='bot.commands',
body=body)
def notify_listeners(self, body):
bot = recebeInput.decisoes(recebeInput.devolveEntidade(recebeInput.trataJson(body)))
for listener in self.event_listeners:
listener.write_message(bot)
print ('PikaClient: notified %s' % repr(listener))
def add_event_listener(self, listener):
print ("added listener")
self.event_listeners.add(listener)
print ('PikaClient: listener %s added' % repr(listener))
def remove_event_listener(self, listener):
try:
self.event_listeners.remove(listener)
print ('PikaClient: listener %s removed' % repr(listener))
except KeyError:
pass
def main():
parse_command_line()
aplication = tornado.web.Application([
(r'/ws', MyWebSocketHandler)
])
# server = tornado.httpserver.HTTPServer(aplication)
io_loop = tornado.ioloop.IOLoop.instance()
# PikaClient is our rabbitmq consumer
pc = PikaClient(io_loop)
aplication.pc = pc
aplication.pc.connect()
aplication.listen(8081)
io_loop.start()
if __name__ == '__main__':
main()
websocket_1 | PikaClient: connected to RabbitMQ
websocket_1 | PikaClient: Channel open, Declaring exchange
websocket_1 | Declaring exchange %s amq.topic
websocket_1 | Exchange declared
websocket_1 | Declaring queue %s bot.commands
rabbit1_1 | 2018-07-17 15:48:18.792 [info] <0.6936.0> connection
<0.6936.0> (172.18.0.1:37556 -> 172.18.0.6:5672): user 'guest' authenticated and granted access to vhost '/'
websocket_1 | [W 180717 15:48:18 channel:1034] Received remote Channel.Close (406): "PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'bot.commands' in vhost '/': received 'false' but current is 'true'" on <Channel number=1 OPEN conn=<TornadoConnection OPEN socket=('172.18.0.2', 47986)->('192.168.99.100', 5672) params=<ConnectionParameters host=192.168.99.100 port=5672 virtual_host=/ ssl=False>>>
websocket_1 | [I 180717 15:48:24 web:2162] 101 GET /ws (192.168.99.1) 1.29ms
websocket_1 | added listener
websocket_1 | PikaClient: listener <__main__.MyWebSocketHandler object at 0x7f483b277cf8> added
websocket_1 | WebSocket opened
最佳答案
队列可能已经存在并且是持久的,所以当您的库尝试预订它并看到持久的队列时,它将引发错误,因为它期望的是非持久队列
关于python-3.x - 队列的等价arg 'durable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51385700/
我有这个代码。为了让它工作,我必须使用 Args&&... 而不是 Args... 或 Args&... 我注意到 args 从 & 转换为 const& 或 && 转换为 &。 Args...Arg
当我定义类时,我总是去 Class A(object): def __init__(self, arg): self.arg = arg def print_arg(s
假设我想定义两个 {Type} 类的变量。构造函数采用 1 个参数。下面两种方式是否完全等价(编译成相同的目标代码)? Type a(arg), b(arg); 和 Type a(arg); Type
(旁白:我是一名 Perl 程序员,正如您所知,这是我的第一个重要的 Java 程序。简单的术语将不胜感激。) 我有以下启动器作为编码工作: import java.lang.reflect.*; i
Math.nextUp(arg) 始终与 arg + Math.ulp(arg) 相同,还是我遗漏了什么? System.out.println( 0.5 + Math.ulp(0.5));
今天我在学习完美转发,我创建了这个代码示例 #include #include template auto toStdFun(Function&& fun, Args&&...ar
我想知道你会选择哪个选项? putStrLn (show randomNum) putStrLn $ show randomNum (putStrLn . show) randomNum 所有选项在语
我试图在 visual studio 2012 中编译一个库,它最初是用 c++ 为 visual studio 2015 编写的。我有一个错误说 'class' missing tag。 错误消息的
我在下面的代码中遇到了运行时异常ArrayIndexOutOfBoundException,行中: if ( args[0].equals("t") || args[0].equals("time")
我有以下代码 import React, { Component } from "react"; import { Accounts } from "meteor/accounts-base"; ex
这个问题已经有答案了: Difference between Arrays and 3 dots (Varargs) in java (3 个回答) 已关闭 5 年前。 受学校线性代数 I 和 II
所以我定义了一个函数: def getDistnace(self, strings, parentD, nodeName, nodeDistance): 我用它来调用: Node.getDistnac
这个问题在这里已经有了答案: subprocess.call() arguments ignored when using shell=True w/ list [duplicate] (2 个答案
我想将参数传递给 java 应用程序,但喜欢 linux 应用程序风格。 java 中的main 方法对所有参数使用一个String 数组。在 Linux 中,大多数应用程序接受如下参数:ls -l
这是我的代码片段 #include void change(int a[]){ printf("%p\n",&a); } int main(){
我需要使用 python 3.6 subprocess.run() 函数发出以下命令: gsettings set org.gnome.shell enabled-extensions "['appl
这两个函数是否有任何有意义的不同?有什么理由通常更喜欢一个而不是另一个吗? void foo(auto x, auto &... y) { /* ... */ } template void foo(
例如: def m(arg, ...args) { println "arg: $arg" println "args: $args" } m('arg', k:'v') 输出: ar
我对 Java 还很陌生。目前正在尝试将 args[] 中给出的文件名传递给此 FileReader,但当我编译时,它说找不到指定的文件。如果我对文件名进行硬编码,它就可以正常工作。这应该如何运作?
为什么这是一个语法错误??做这件事的合适方法是什么? >>> def f(*args, option=None): File "", line 1 def f(*args, option=
我是一名优秀的程序员,十分优秀!