Objective C - "Hello world" tutorial is not working in "receive" part

479 views
Skip to first unread message

G.Y.

unread,
Aug 10, 2016, 4:24:26 AM8/10/16
to rabbitmq-users
Hi, i'm new at these server-client connections with RabbitMQ. I downloaded and run server and implemented tutorial in my view controller. However, when i run the example code. In receive part i get these errors: 

Received connection: <RMQConnection: 0x17e87200> disconnectedWithError: Error Domain=NSPOSIXErrorDomain Code=0 "Undefined error: 0" UserInfo={NSLocalizedFailureReason=Error in connect() function, NSLocalizedDescription=Undefined error: 0}

Received connection: <RMQConnection: 0x17d84520> disconnectedWithError: Error Domain=NSPOSIXErrorDomain Code=0 "Undefined error: 0" UserInfo={NSLocalizedFailureReason=Error in connect() function, NSLocalizedDescription=Undefined error: 0}

Received connection: <RMQConnection: 0x17e87200> failedToConnectWithError: Error Domain=com.rabbitmq.rabbitmq-objc-client Code=1 "Handshake timed out." UserInfo={NSLocalizedDescription=Handshake timed out.}

Received connection: <RMQConnection: 0x17d84520> failedToConnectWithError: Error Domain=com.rabbitmq.rabbitmq-objc-client Code=1 "Handshake timed out." UserInfo={NSLocalizedDescription=Handshake timed out.}

Starting recovery for connection: <RMQConnection: 0x17d84520>

Will start recovery for connection: <RMQConnection: 0x17d84520>

Received connection: <RMQConnection: 0x17d84520> disconnectedWithError: Error Domain=NSPOSIXErrorDomain Code=3 "No such process" UserInfo={NSLocalizedFailureReason=Error in connect() function, NSLocalizedDescription=No such process}

Received connection: <RMQConnection: 0x17d84520> failedToConnectWithError: Error Domain=com.rabbitmq.rabbitmq-objc-client Code=1 "Handshake timed out." UserInfo={NSLocalizedDescription=Handshake timed out.}


I really don't know what to do. I saw some posts in StackOverflow, suggesting downloading Erlang but its already installed in my computer. 

If someone can help me, i'll go forward. Thanks :)

Michael Klishin

unread,
Aug 10, 2016, 5:54:28 AM8/10/16
to rabbitm...@googlegroups.com
If you want to get help, consider posting your code and server logs.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Andrew Bruce

unread,
Aug 10, 2016, 6:02:08 AM8/10/16
to rabbitm...@googlegroups.com
From what you've posted, I'd say that the server isn't running or isn't accessible. The tutorials assume the server is running locally using default ports.

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

G.Y.

unread,
Aug 12, 2016, 2:40:49 AM8/12/16
to rabbitmq-users
My code is exactly the same with the tutorial's Hello World part which is written in Objective-C. However, still it is:

- (void)viewDidLoad {

 

   
[super viewDidLoad];


 

   
// running /usr/local/sbin/rabbitmq-server from terminal

     

   
[self send];

   
[self receive];

}




- (void)send {

   

   
NSLog(@"Attempting to connect to local RabbitMQ broker");

   
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];

   
[conn start];

   

    id
<RMQChannel> ch = [conn createChannel];

   

   
RMQQueue *q = [ch queue:@"hello"];

   

   
[ch.defaultExchange publish:[@"Hello World!" dataUsingEncoding:NSUTF8StringEncoding] routingKey:q.name];

   
NSLog(@"Sent 'Hello World!'");

   

   
[conn close];

   

}




- (void)receive {

   

   
NSLog(@"Attempting to connect to local RabbitMQ broker");

   
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];

   
[conn start];

   

    id
<RMQChannel> ch = [conn createChannel];

   

   
RMQQueue *q = [ch queue:@"hello"];

   
NSLog(@"Waiting for messages.");

   
[q subscribe:^(RMQMessage * _Nonnull message) {

       
NSLog(@"Received %@", [[NSString alloc] initWithData:message.body encoding:NSUTF8StringEncoding]);

   
}];

   
NSLog(@"end of receiving");

 

}


Server logs are nothing. It just says "started" and noone is coming or going. 


I tried to run code again and get:


2016-08-12 09:31:25.307 tutorial[828:381859] Attempting to connect to local RabbitMQ broker

2016-08-12 09:31:25.380 tutorial[828:381859] Sent 'Hello World!'

2016-08-12 09:31:25.381 tutorial[828:381859] Attempting to connect to local RabbitMQ broker

2016-08-12 09:31:25.384 tutorial[828:381859] Waiting for messages.

2016-08-12 09:31:25.385 tutorial[828:381859] end of receiving

2016-08-12 09:31:25.686 tutorial[828:382125] Received connection: <RMQConnection: 0x156bad90> disconnectedWithError: Error Domain=NSPOSIXErrorDomain Code=0 "Undefined error: 0" UserInfo={NSLocalizedFailureReason=Error in connect() function, NSLocalizedDescription=Undefined error: 0}

2016-08-12 09:31:25.710 tutorial[828:382125] Received connection: <RMQConnection: 0x156d4ba0> disconnectedWithError: Error Domain=NSPOSIXErrorDomain Code=3 "No such process" UserInfo={NSLocalizedFailureReason=Error in connect() function, NSLocalizedDescription=No such process}

2016-08-12 09:31:35.376 tutorial[828:382139] Received connection: <RMQConnection: 0x156bad90> failedToConnectWithError: Error Domain=com.rabbitmq.rabbitmq-objc-client Code=1 "Handshake timed out." UserInfo={NSLocalizedDescription=Handshake timed out.}

2016-08-12 09:31:35.390 tutorial[828:382139] Received connection: <RMQConnection: 0x156d4ba0> failedToConnectWithError: Error Domain=com.rabbitmq.rabbitmq-objc-client Code=1 "Handshake timed out." UserInfo={NSLocalizedDescription=Handshake timed out.}


Then it tries recovery and gets the same result. 

I hope i'm clear. 

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Andrew Bruce

unread,
Aug 12, 2016, 3:50:17 AM8/12/16
to rabbitmq-users
Can you connect to the broker with a different client e.g. Bunny? https://github.com/ruby-amqp/bunny

The errors you're getting are to do with establishing an initial TCP connection. I would focus on ensuring that some connection can be made before trying to debug a particular client.

Thanks,

Andrew

G.Y.

unread,
Aug 12, 2016, 4:30:32 AM8/12/16
to rabbitmq-users
I just tried Java tutorial in both localhost and other computer and get correct outputs. In other words, my problem is about Objective-C. Does this mean something?

Andrew Bruce

unread,
Aug 12, 2016, 7:13:02 AM8/12/16
to rabbitmq-users
Can you post the (redacted, if necessary) code you used to connect to both Java and the Objective-C code that is failing?

On Fri, Aug 12, 2016 at 9:30 AM G.Y. <ylmz...@gmail.com> wrote:
I just tried Java tutorial in both localhost and other computer and get correct outputs. In other words, my problem is about Objective-C. Does this mean something?

--

Andrew Bruce

unread,
Aug 12, 2016, 7:15:38 AM8/12/16
to rabbitmq-users
Apologies, I see the ObjC code, so it's just the Java code that's missing.

Andrew Bruce

unread,
Aug 12, 2016, 7:20:22 AM8/12/16
to rabbitmq-users
Otherwise, the main difference between these clients is that ObjC uses 127.0.0.1 by default, whereas Java uses localhost.


Andrew Bruce

unread,
Aug 12, 2016, 7:22:20 AM8/12/16
to rabbitmq-users
I'm a liar. Objective-C uses "localhost".

G.Y.

unread,
Aug 15, 2016, 2:31:42 AM8/15/16
to rabbitmq-users
Sorry for being late. 

I copied Java code from tutorial, exactly the same of it. 

Send.java

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Send {
 
private final static String QUEUE_NAME = "hello";

 
public static void main(String[] argv) throws Exception {

   
ConnectionFactory factory = new ConnectionFactory();
   
factory.setHost("localhost");
   
Connection connection = factory.newConnection();
   
Channel channel = connection.createChannel();

    channel
.queueDeclare(QUEUE_NAME, false, false, false, null);
   
String message = "Hello World!";
    channel
.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
   
System.out.println(" [x] Sent '" + message + "'");

    channel
.close();
    connection
.close();
 
}
}


and Recv.Java


import com.rabbitmq.client.*;
import java.io.IOException;

public class Recv {
 
private final static String QUEUE_NAME = "hello";

 
public static void main(String[] argv) throws Exception {

   
ConnectionFactory factory = new ConnectionFactory();
    factory
.setHost("localhost");
   
Connection connection = factory.newConnection();
   
Channel channel = connection.createChannel();

    channel
.queueDeclare(QUEUE_NAME, false, false, false, null);
   
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

   
Consumer consumer = new DefaultConsumer(channel) {

     
@Override
     
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
         
throws IOException {
       
String message = new String(body, "UTF-8");
       
System.out.println(" [x] Received '" + message + "'");
     
}
   
};
    channel
.basicConsume(QUEUE_NAME, true, consumer);
 
}
}


I put breakpoints and see that i generally get no error while sending (in objective-c). However, while receiving [conn start] gives first error. 


Received connection: <RMQConnection: 0x146bde10> failedToConnectWithError: Error Domain=com.rabbitmq.rabbitmq-objc-client Code=1 "Handshake timed out." UserInfo={NSLocalizedDescription=Handshake timed out.}


I thought about hanshake time but i know it's not the problem. Still if you think config file can fix the problem, maybe you can tell me what to write in that file. 


Thanks for your help. 

Michael Klishin

unread,
Aug 15, 2016, 2:37:35 AM8/15/16
to rabbitm...@googlegroups.com
It means that TCP connection succeeded but the client then didn't finish (or even begin) the AMQP 0-9-1
handshake.

What is in server logs around the time it happens?

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

G.Y.

unread,
Aug 15, 2016, 3:06:25 AM8/15/16
to rabbitmq-users
There's notging in server logs. For today's connection, it is all:

=INFO REPORT==== 15-Aug-2016::09:36:46 ===
Starting RabbitMQ 3.6.1 on Erlang 18.3
Copyright (C) 2007-2016 Pivotal Software, Inc.
Licensed under the MPL.  See http://www.rabbitmq.com/


=INFO REPORT==== 15-Aug-2016::09:36:46 ===
node          
: rabbit@localhost
home dir      
: /Users/gamze
config file
(s) : /usr/local/etc/rabbitmq/rabbitmq.config (not found)
cookie hash    
: xSAWSSXW4feFRoZTvjFwXg==
log            
: /usr/local/var/log/rabbitmq/rabbit@localhost.log
sasl log      
: /usr/local/var/log/rabbitmq/rabbit@localhost-sasl.log
database dir  
: /usr/local/var/lib/rabbitmq/mnesia/rabbit@localhost


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
Memory limit set to 3178MB of 7947MB total.


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
Disk free limit set to 50MB


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
Limiting to approx 156 file handles (138 sockets)


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
FHC read buffering
:  OFF
FHC write buffering
: ON


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
Priority queues enabled, real BQ is rabbit_variable_queue


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
Management plugin: using rates mode 'basic'


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
msg_store_transient
: using rabbit_msg_store_ets_index to provide index


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
msg_store_persistent
: using rabbit_msg_store_ets_index to provide index


=WARNING REPORT==== 15-Aug-2016::09:36:50 ===
msg_store_persistent
: rebuilding indices from scratch


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
started TCP
Listener on 127.0.0.1:5672


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
rabbit_stomp
: default user 'guest' enabled


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
started STOMP TCP
Listener on [::]:61613


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
MQTT retained message store
: rabbit_mqtt_retained_msg_store_dets


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
started MQTT TCP
Listener on [::]:1883


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
Management plugin started. Port: 15672


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
Statistics database started.


=INFO REPORT==== 15-Aug-2016::09:36:50 ===
Server startup complete; 10 plugins started.
 
* rabbitmq_management_visualiser
 
* rabbitmq_management
 
* rabbitmq_web_dispatch
 
* webmachine
 
* mochiweb
 
* rabbitmq_mqtt
 
* rabbitmq_stomp
 
* rabbitmq_amqp1_0
 
* rabbitmq_management_agent
 
* amqp_client



By the way, with Java i tried to connect other computer again and succeeded. In fact, i want to try it with objective-c but i don't know how to put username and password.  

Michael Klishin

unread,
Aug 15, 2016, 3:26:14 AM8/15/16
to rabbitm...@googlegroups.com
There are no accepted connections in the provided log. Successful client library
connections are always logged by default: was the config file modified?

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

G.Y.

unread,
Aug 15, 2016, 3:33:17 AM8/15/16
to rabbitmq-users
RabbitMQ does not give an abstract config file at first as i know (and guess). Server log says "not found" either. I thought i can create one but not sure to give/write what for what. Thus, i left it. If you tell me, i can make it.

Michael Klishin

unread,
Aug 15, 2016, 3:38:08 AM8/15/16
to rabbitm...@googlegroups.com
If you don't have a config then all defaults are used and both successful and failed connections
should be logged (any connection that sends at least some data after the TCP connection is accepted, to be specific).

There is an example config [1] but RabbitMQ does not require that you configure anything by default.

Back to my original point: there are no inbound connections in the log posted. Which means that either
your Java code connects to a different node or it doesn't actually connect. 
How do you observe that connection succeeded?

TCP connectivity with any client
are typically immediately visible (in Java, an IOException is thrown by ConnectionFactory#newConnection) but in case
of firewalls that drop traffic, it will take a connection timeout.


On Mon, Aug 15, 2016 at 10:32 AM, G.Y. <ylmz...@gmail.com> wrote:
RabbitMQ does not give an abstract config file at first as i know (and guess). Server log says "not found" either. I thought i can create one but not sure to give/write what for what. Thus, i left it. If you tell me, i can make it. 
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

G.Y.

unread,
Aug 15, 2016, 3:55:28 AM8/15/16
to rabbitmq-users
No no, i did not send you my Java connection server logs. They are written as:

=INFO REPORT==== 15-Aug-2016::10:52:49 ===
accepting AMQP connection
<0.7185.1> (127.0.0.1:50583 -> 127.0.0.1:5672)


=INFO REPORT==== 15-Aug-2016::10:52:49 ===
closing AMQP connection
<0.7185.1> (127.0.0.1:50583 -> 127.0.0.1:5672)


=INFO REPORT==== 15-Aug-2016::10:52:58 ===
accepting AMQP connection
<0.7296.1> (127.0.0.1:50585 -> 127.0.0.1:5672)

Today i didn't connect localhost by Java because i did it in friday. Today i just connected other computer and my friend saw logs. 
The previous server logs were all about objective-c. I was trying localhost by objective-c. 

Michael Klishin

unread,
Aug 15, 2016, 4:03:28 AM8/15/16
to rabbitm...@googlegroups.com
So when you attempt to connect to localhost using the Objective-C client you get nothing in the logs
but a different client connects successfully.

Please use Wireshark to do a traffic capture for the loopback interface:

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

G.Y.

unread,
Aug 15, 2016, 4:17:22 AM8/15/16
to rabbitmq-users
Yes, that is the situation. 

I used Cocoa-Pods for downloading RabbitMQ Client framework. Maybe problem is due to this but, i really don't know. 

I'll use Wireshark then. 

Andrew Bruce

unread,
Aug 15, 2016, 4:52:56 AM8/15/16
to rabbitmq-users
The issue has nothing to do with CocoaPods: you have a working client, it's just failing to complete a connection and handshake with the local broker.

Remember that the Objective-C client is asynchronous, so your send code is probably failing too. Breakpointing probably won't help in this case, as you'll need to look at the objects sent to the delegate to decide whether it's send or receive code that's failing.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

Michael Klishin

unread,
Aug 15, 2016, 5:00:01 AM8/15/16
to rabbitm...@googlegroups.com
Breakpoints also can pause code execution in a way that makes the peer or the client itself believe
that protocol handshake timed out. So I'd recommend trying without using a debugger. The issue is unlikely
to be very involved.

On Mon, Aug 15, 2016 at 11:52 AM, Andrew Bruce <abr...@pivotal.io> wrote:
The issue has nothing to do with CocoaPods: you have a working client, it's just failing to complete a connection and handshake with the local broker.

Remember that the Objective-C client is asynchronous, so your send code is probably failing too. Breakpointing probably won't help in this case, as you'll need to look at the objects sent to the delegate to decide whether it's send or receive code that's failing.
On Mon, Aug 15, 2016 at 9:17 AM G.Y. <ylmz...@gmail.com> wrote:
Yes, that is the situation. 

I used Cocoa-Pods for downloading RabbitMQ Client framework. Maybe problem is due to this but, i really don't know. 

I'll use Wireshark then. 

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

zemel

unread,
Oct 17, 2017, 3:10:12 AM10/17/17
to rabbitmq-users
I get the same error with you. How to solve this problem? Can you give me some guide?
Reply all
Reply to author
Forward
0 new messages