alanxz / rabbitmq-c

RabbitMQ C client
MIT License
1.77k stars 672 forks source link

opening TCP socket: hostname lookup failed #512

Closed WZRPW closed 6 years ago

WZRPW commented 6 years ago

hi, I am trying to rabbmitmq-c to send message to the message queue server. URL: "amqp://svxvaiup:e-fEFcGJZgm2vKk1D7OykIf2GHTBI16z@eagle.rmq.cloudamqp.com/svxvaiup" I used amqp_connect_timeout.exe to test the connection. But it could not open TCP socket.

amqp_connect_timeout.exe "amqp://svxvaiup:e-fEFcGJZgm2vKk1D7OykIf2GHTBI16z@eagle.rmq.cloudamqp.com/svxvaiup" 5672 5 opening TCP socket: hostname lookup failed

Actually my Python script could successfully establish TCP connection. The Python script did not need port and exchange was empty (I do not know why it does not need them). ######################################################## """Create AMQP Client""" import json import pika class CloudAMQPClient: """AMQP client generator"""

def __init__(self, cloud_amqp_url, queue_name):
    """Initialization AMQP Client"""
    print('Run AMQP Remote.')
    self.cloud_amqp_url = cloud_amqp_url
    self.queue_name = queue_name
    self.params = pika.URLParameters(cloud_amqp_url)
    self.params.socket_timeout = 3
    self.connection = pika.BlockingConnection(self.params)
    self.channel = self.connection.channel()
    self.channel.queue_declare(queue=queue_name)

def send_message(self, message):
    """Send Message"""
    self.channel.basic_publish(exchange='',
                               routing_key=self.queue_name,
                               body=json.dumps(message))
    print('[x] sent message to %s:%s' % (self.queue_name, message))

########################################################

I do not have much knowledge about rabbitmq. Thank you!

alanxz commented 6 years ago

amqp_connect_timeout.c expectes 2 command-line parameters: host and port. You've supplied an AMQP URL. The amqp_connect_timeout example would need to be modified for your needs.