2017-10-12 13 views
-2

RabbitMQ & python pikaで2つのホストを接続しようとしています。ここでリモートRabbitMQサーバーへの接続中にAccessDeniedError

は労働者である:

sudo rabbitmqctl add_user login-to-remote pass 

そして私:私はコマンドを使用して、両方のホスト上の2人のユーザーを作成しました

#!/usr/bin/env python 
import pika, sys 
WORKER_IP = '192.168.0.3' 
credentials = pika.PlainCredentials('login-to-remote', 'pass') 
connection = pika.BlockingConnection(pika.ConnectionParameters(
     host=WORKER_IP, socket_timeout=300, credentials=credentials)) 
channel = connection.channel() 

channel.queue_declare(queue='task_queue', durable=True) 

message = ' '.join(sys.argv[1:]) or "Hello World!" 
channel.basic_publish(exchange='', 
         routing_key='task_queue', 
         body=message, 
         properties=pika.BasicProperties(
         delivery_mode = 2, # make message persistent 
        )) 
print(" [x] Sent %r" % message) 
connection.close() 

#!/usr/bin/env python 
import pika, time 
NEW_TASK_HOST_IP = '192.168.0.2' 
credentials = pika.PlainCredentials('login-to-remote', 'pass') 
connection = pika.BlockingConnection(
        pika.ConnectionParameters(host=NEW_TASK_HOST_IP)) 
channel = connection.channel() 

channel.queue_declare(queue='task_queue', durable=True) 
print(' [*] Waiting for messages. To exit press CTRL+C') 

def callback(ch, method, properties, body): 
    ch.basic_ack(delivery_tag = method.delivery_tag) 

channel.basic_qos(prefetch_count=1) 
channel.basic_consume(callback, 
         queue='task_queue') 

そして、ここでは、新しいタスクであります私が持っているものを動かそうとしている:

Traceback (most recent call last): 
    File "worker.py", line 5, in <module> 
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=NEW_TASK_HOST_IP, socket_timeout=300, credentials=credentials)) 
    File "/home/anna/.local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 374, in __init__ 
    self._process_io_for_connection_setup() 
    File "/home/anna/.local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 414, in _process_io_for_connection_setup 
    self._open_error_result.is_ready) 
    File "/home/anna/.local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 466, in _flush_output 
    raise maybe_exception 
pika.exceptions.ProbableAccessDeniedError: (-1, "error(104, 'Connection reset by peer')") 

私は両方の方向にUDPとTCPの両方のためのiperfとホスト間の接続をチェックしました:

iperf -s -p 5672 
iperf -p 5672 -c 192.168.0.2 

だからトラフィックが行きます。

私はうまくスタックしていますが、何が問題になりますか?

答えて

1
connection = pika.BlockingConnection(
        pika.ConnectionParameters(host='new-task-host-ip')) 

. 
. 
. 

connection = pika.BlockingConnection(pika.ConnectionParameters(
    host='worker-ip', socket_timeout=300, credentials=credentials)) 

'new-task-host-ip'および'worker-ip'は無効なIPアドレスです。これらをホストの実際のIPアドレス(おそらく'localhost'または'127.0.0.1)に置き換える必要があります。

+0

はい、これは単なる例ですが、これらの文字列の代わりに実際のIPがあります。わかりやすくするためにこの文字列をIPで変更します。 – Kirill

+0

@Kirillこの質問は、ネットワークとプログラミングに関するものです。ファイアウォールの設定、関連するポート転送などを確認してください。 – DeepSpace

+0

RabbitMQポートのiperfとの接続を確認しましたが、すべて問題ありません。 – Kirill

関連する問題