0

I am working on to integrate cloud AMPQ to my iOS app. With RabbitMQ client, unable to make successful communication with the server.

I have checked below stack overflow link to make a communication with the server: stack overflow link

The sample source shared in above link broken. Please suggest me possible solution. Thanks in advance

kalai
  • 56
  • 8
  • you get any console report for break connection – Anbu.Karthik Aug 28 '17 at 09:53
  • Actually, If I add RabbitMq-C library to main source that will throw lot of errors like "htonll - not found", some default error key not found(XMLTO_EXECUTABLE). If you have setup(code) to make communication with subscribe and publish services. Share me – kalai Aug 28 '17 at 10:20
  • can you add your errors – Anbu.Karthik Aug 28 '17 at 10:27
  • I tried 2 methods, In first method while make communication with RabbitMQclient ( https://github.com/rabbitmq/rabbitmq-objc-client ), I get two errors randomly 1. borken pipe 2. handshake timeout In second method with RabbitMq-C library( https://github.com/alanxz/rabbitmq-c ) and librabbitmq-objc( https://github.com/profmaad/librabbitmq-objc ), I got some errors like "htonll - not found" and some default error key not found(XMLTO_EXECUTABLE) in integrating libraries into main source. – kalai Aug 29 '17 at 12:38
  • can you add your console error – Anbu.Karthik Aug 29 '17 at 12:45
  • Why not use https://github.com/rabbitmq/rabbitmq-objc-client instead ? The example works perfectly with a RabbitMQ server (https://github.com/rabbitmq/rabbitmq-objc-client/#basic-usage-example) – nathan Aug 30 '17 at 02:36
  • @Nathan, I am using the remote AMPQ URI, Not localhost. with this case, I need to give username, password and unique client id(used for unique device identification) configured in server. From RabbitMQ, How can i pass credentials to make communication?. Please add your suggestion. Thanks – kalai Aug 30 '17 at 12:28
  • Have you tried searching their repo ? Auth using user/password: https://github.com/rabbitmq/rabbitmq-objc-client/issues/123 – nathan Aug 30 '17 at 14:27
  • @Nathan, I also used above library with crdentials (uesrname/password). But that throws an error "socket connection closed by remote peer" – kalai Aug 31 '17 at 14:34
  • @Nathan, I tried all posibilities. Each one one has some curdles. I am struck in half way. I thing, i need to configure client id, while making connection request. I don't know how to set client id to make an connection with servet. Help me. Thankyou – kalai Aug 31 '17 at 14:44
  • The client ID along with the credentials can be sent using the provided connection string. Heroku for example already provides a ready to use connection string that includes the user/password/clientId/system key/etc https://www.rabbitmq.com/uri-query-parameters.html – nathan Aug 31 '17 at 15:06
  • Okay. I will check – kalai Aug 31 '17 at 15:59

1 Answers1

1

You should use the official client library: https://github.com/rabbitmq/rabbitmq-objc-client (Swift + ObjC compatible)

Basic Usage (extract from repo):

  1. Instantiate an RMQConnection:

    let delegate = RMQConnectionDelegateLogger() // implement RMQConnectionDelegate yourself to react to errors
    let conn = RMQConnection(uri: "amqp://guest:guest@localhost:5672", delegate: delegate)
    
  2. Connect:

    conn.start()
    
  3. Create a channel:

    let ch = conn.createChannel()
    
  4. Use the channel:

    let q = ch.queue("myqueue")
    q.subscribe({ m in
        print("Received: \(String(data: m.body, encoding: String.Encoding.utf8))")
    })
    q.publish("foo".data(using: String.Encoding.utf8))
    
  5. Close the connection when done:

    conn.close()
    

Depending on the provider, you'll need to construct the connection URI manually. Heroku for example already presents it in it's dashboard. Here's the documentation on the supported parameters: https://www.rabbitmq.com/uri-spec.html and https://www.rabbitmq.com/uri-query-parameters.html

Example URI on Heroku:

amqp://xxxxxxx:yyy-zzz@aaaaaa.bigwig.lshift.net:10674/bbbbbbb

Format:

amqp_URI = "amqp://" [ username [ ":" password ] "@" ] host [ ":" port ] [ "/" vhost ] [ "?" query ]
nathan
  • 9,329
  • 4
  • 37
  • 51