简体   繁体   中英

Cannot send to rpc_server my request i am using RabbitMQ on Heroku with pika

I just set up a RabbitMQ add-on in heroku. After developing my app to queue up and consume messages running on a local instance, I deployed it to Heroku and have not been able to send my message successfully yet.

the rpc_queue never receive anything, my urls are corrects and my rpc_server listen well but never receive anything

server.py

parameters = pika.URLParameters('amqp://djeo4uf8:f4323HekqiVXgt_vlnqPfJnvJruzszbn@sad-groundsel-39.bigwig.lshift.net:10723/fl1sX7CbcDds')        
    connection = pika.BlockingConnection(parameters)

    channel = connection.channel()

    channel.queue_declare(queue='rpc_queue')

    def on_request(ch, method, props, body):            
        data = loads( b64decode(body) )
        response = getattr(functions, data["command"] )(data["args"])   
        response =  b64encode( dumps(response) )

        ch.basic_publish(exchange='',
                         routing_key=props.reply_to,
                         properties=pika.BasicProperties(correlation_id = \
                                                             props.correlation_id),
                         body=str(response))
        ch.basic_ack(delivery_tag = method.delivery_tag)

    channel.basic_qos(prefetch_count=1)
    channel.basic_consume(on_request, queue='rpc_queue')

    print(" [x] Awaiting RPC requests")
    channel.start_consuming()   

client.py

class RpcClient(object):
    def __init__(self):
        parameters = pika.URLParameters('amqp://djeo4uf8:f4323HekqiVXgt_vlnqPfJnvJruzszbn@sad-groundsel-39.bigwig.lshift.net:10722/fl1sX7CbcDds') 
        parameters.socket_timeout = 5
        self.connection = pika.BlockingConnection(parameters)
        self.channel = self.connection.channel()

        result = self.channel.queue_declare(exclusive=True)
        self.callback_queue = result.method.queue

        self.channel.basic_consume(self.on_response, no_ack=True,
                                   queue=self.callback_queue)

    def on_response(self, ch, method, props, body):     
        if self.corr_id == props.correlation_id:
            self.response =loads( b64decode(body) )

    def call(self, dict_data):
        self.response = None
        self.corr_id = str(uuid.uuid4())
        self.channel.basic_publish(exchange='',
                                   routing_key='rpc_queue',
                                   properties=pika.BasicProperties(
                                         reply_to = self.callback_queue,
                                         correlation_id = self.corr_id,
                                         ),
                                   body=b64encode( dumps(dict_data) ) )

        while self.response is None:             
            self.connection.process_data_events()
        self.channel.close()
        self.connection.close() 
        return self.response

so i do the call and i never receive anything because my rpc_queue always is empty

rpc = RpcClient()           
response = rpc.call(payloadObj)

Much thanks in advance!

在服务器和客户端中使用不同的端口1072310722来发送消息,以接收消息,它应该是在两个端口上都监听的同一RabbitMQ节点,或者是具有HA队列的群集节点。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM