rabbitmq-cpp-tutorials
rabbitmq-cpp-tutorials copied to clipboard
Suggested changes to use IP address
https://stackoverflow.com/q/50402938/1466825
NOTE: this is COMPLETELY untested as I can't build the project on my workstation.
The error is very clear -
error: prototype for ‘SimplePocoHandler::SimplePocoHandler(const Poco::Net::IPAddress&, uint16_t)’ does not match any in class ‘SimplePocoHandler’
Like I said, this is completely untested code. I didn't put a prototype for that constructor into this file. I will fix this error but from here on out you're on your own 😺
Thank you for everything Luke. I am still getting errors, I understand it is untested code. I will try to see if I can fix the errors.
[ 93%] Building CXX object src/CMakeFiles/send.dir/send.cpp.o /home/pi/rabbitmq-cpp-tutorials/src/send.cpp: In function ‘int main()’: /home/pi/rabbitmq-cpp-tutorials/src/send.cpp:11:33: error: invalid conversion from ‘const AMQP::ConnectionHandler*’ to ‘AMQP::ConnectionHandler*’ [-fpermissive] AMQP::Connection connection(&handler, AMQP::Login("test", "test"), "/"); ^~~~~~~~ In file included from /home/pi/rabbitmq-cpp-tutorials/3rdparty/AMQP-CPP-2.1.4/amqpcpp.h:71:0, from /home/pi/rabbitmq-cpp-tutorials/src/SimplePocoHandler.h:5, from /home/pi/rabbitmq-cpp-tutorials/src/send.cpp:4: /home/pi/rabbitmq-cpp-tutorials/3rdparty/AMQP-CPP-2.1.4/amqpcpp/connection.h:36:5: note: initializing argument 1 of ‘AMQP::Connection::Connection(AMQP::ConnectionHandler*, const AMQP::Login&, const string&)’ Connection(ConnectionHandler *handler, const Login &login, const std::string &vhost) : _implementation(this, handler, login, vhost) {} ^~~~~~~~~~ /home/pi/rabbitmq-cpp-tutorials/src/send.cpp: In lambda function: /home/pi/rabbitmq-cpp-tutorials/src/send.cpp:20:26: error: passing ‘const SimplePocoHandler’ as ‘this’ argument discards qualifiers [-fpermissive] handler.quit(); ^ In file included from /home/pi/rabbitmq-cpp-tutorials/src/send.cpp:4:0: /home/pi/rabbitmq-cpp-tutorials/src/SimplePocoHandler.h:22:10: note: in call to ‘void SimplePocoHandler::quit()’ void quit(); ^~~~ /home/pi/rabbitmq-cpp-tutorials/src/send.cpp: In function ‘int main()’: /home/pi/rabbitmq-cpp-tutorials/src/send.cpp:24:18: error: passing ‘const SimplePocoHandler’ as ‘this’ argument discards qualifiers [-fpermissive] handler.loop(); ^ In file included from /home/pi/rabbitmq-cpp-tutorials/src/send.cpp:4:0: /home/pi/rabbitmq-cpp-tutorials/src/SimplePocoHandler.h:21:10: note: in call to ‘void SimplePocoHandler::loop()’ void loop(); ^~~~ src/CMakeFiles/send.dir/build.make:62: recipe for target 'src/CMakeFiles/send.dir/send.cpp.o' failed make[3]: *** [src/CMakeFiles/send.dir/send.cpp.o] Error 1 CMakeFiles/Makefile2:320: recipe for target 'src/CMakeFiles/send.dir/all' failed make[2]: *** [src/CMakeFiles/send.dir/all] Error 2 CMakeFiles/Makefile2:332: recipe for target 'src/CMakeFiles/send.dir/rule' failed make[1]: *** [src/CMakeFiles/send.dir/rule] Error 2 Makefile:170: recipe for target 'send' failed make: *** [send] Error 2
Remove const from const SimplePocoHandler in send.cpp. I'm clearly not a good C++ programmer these days 😉
Thank you! Nothing is showing up in localhost:15672/queues when I execute the 'send' code after making it with cmake.
I've modified 'send'. Mainly just changing the ip address to my current one and 5672 to 15672
#include
#include "SimplePocoHandler.h"
int main(void) { const Poco::Net::IPAddress ip("10.110.147.224"); SimplePocoHandler handler(ip, 15672);
AMQP::Connection connection(&handler, AMQP::Login("test", "test"), "/");
AMQP::Channel channel(&connection);
channel.onReady([&]()
{
if (handler.connected())
{
channel.publish("", "Raphael", "Cowabunga!");
std::cout << " [x] Sent " << std::endl;
handler.quit();
}
});
handler.loop();
return 0;
}
I've tried both localhost and an IP address but nothing is showing up in the rmq management console/plugin plus I never get the confirmation [X] Sent Hello World in the terminal.
You need to make sure you are publishing to a queue that exists and that this code is correct:
channel.publish("", "Raphael", "Cowabunga!");
You should also check your RabbitMQ server logs to ensure that a connection is actually being recorded. You may consider running Wireshark to view traffic on port 5672
This queue exists on the ip address (10.110.147.224) I am entering. I've succesfully been able to send it messages with my java code on another pc
I've also just created the queue "Raphael" on localhost but still, it receives nothing
Why are you using port 15672? That is typically the management API port.
Are you certain you are using the same values as your Java code?
Again, without more information I can only suggest doing a packet capture and comparing your successful Java app with this one.
You're right I should be using 5672. It is not specified in my Java code (below), but it is using it by default.
When using 5672 in the C++ code it executes with 10.110.147.224, , but again nothing shows up in the queue.
I've installed wireshark and when using the UI, I filtered by amqp nothing comes up. When I filter by tcp.port==5672 I get a couple packets like this...
3755 394.469380600 10.110.25.150 10.110.147.224 TCP 74 [TCP Retransmission] 36912 → 5672 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=173473758 TSecr=0 WS=128
public class main {
public static void main(String[] arg) throws Exception {
//Timing out? change the IP!
String ip="10.110.147.224";
String Pi1Q1="Leonardo";
String Pi1Q2="Raphael";
String Pi2Q3="Donatello";
String Pi2Q4="Michelangelo";
Send.send(ip, Pi1Q1);
Send.send(ip, Pi1Q2);
Send.send(ip, Pi2Q3);
Send.send(ip, Pi2Q4);
Recv.recv(ip, Pi1Q1);
Recv.recv(ip, Pi1Q2);
Recv.recv(ip, Pi2Q3);
Recv.recv(ip, Pi2Q4);
}
}
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
public class Send {
public static void send(String ip, String Q) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
//set connection info
factory.setHost(ip);
factory.setUsername("test");
factory.setPassword("test");
//create connection
Connection connection = factory.newConnection();
//create channel
Channel channel = connection.createChannel();
//publish message
int a = 1;
while (a!=0)
{
channel.queueDeclare(Q, false, false, false, null);
for(int i=1; i<=2; i++)
{
String message = "Pizza #"+i;
channel.basicPublish("", Q, null, message.getBytes("UTF-8"));
System.out.println(" [x] Sent '" + message + "'" + Q);
}
a--;
}
//SHUT IT ALL DOWN!
channel.close();
connection.close();
}
}
After doing more research it seems that this has to do with my firewall. When I telenet the Ip address I want to connect to from the Pi, it times out.
Now I am trying to see how to open up the ports on my PC. I've followed this guide: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-a-windows-firewall-for-database-engine-access?view=sql-server-2017 and made 2 inbound rules to accept connections for Ports 5672 and 15672 but to no avail so far.
Ok it was the firewall. After restarting I no longer have that issue.
However I am getting AMQP error invalid end of frame marker when I run the Send executable.
I've attached my wireshark file in this thread https://groups.google.com/forum/?nomobile=true#!topic/rabbitmq-users/OF-FYIuUaqg
Can you tell me what is going wrong?
Wireshark Packet Summaries:
10 0.137072440 192.168.137.72 192.168.137.127 TCP 74 51138 → 5672 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=680864689 TSecr=0 WS=128
20 0.150815883 192.168.137.127 192.168.137.72 TCP 66 5672 → 51138 [SYN, ACK] Seq=0 Ack=1 Win=17520 Len=0 MSS=1460 WS=256 SACK_PERM=1
21 0.151000159 192.168.137.72 192.168.137.127 TCP 54 51138 → 5672 [ACK] Seq=1 Ack=1 Win=29312 Len=0
22 0.151602105 192.168.137.72 192.168.137.127 AMQP 62 Protocol-Header 0-9-1
23 0.168308764 192.168.137.127 192.168.137.72 AMQP 546 Connection.Start
24 0.168486582 192.168.137.72 192.168.137.127 TCP 54 51138 → 5672 [ACK] Seq=9 Ack=493 Win=30336 Len=0
55 10.179104049 192.168.137.127 192.168.137.72 TCP 54 5672 → 51138 [RST, ACK] Seq=493 Ack=9 Win=0 Len=0
At this point there's most likely a bug in this code. You can see that the connection appears to be established and the AMQP handshake completed, but then your code stalls.
I suggest comparing this packet capture with one from the Java application you mention to see where the difference lies.
If you're not aware, AMQP-CPP has a much newer version here, with some examples here. I would recommend using one of their suggested event loops rather than coding your own.
I've added a packet reading screenshot here: https://groups.google.com/forum/#!topic/rabbitmq-users/TDfV2TV8xtg from my successful java program.
I've replaced the AMQP-CPP files with the newest versions but I still get the same error. I do not see how this example https://github.com/CopernicaMarketingSoftware/AMQP-CPP/blob/master/examples/libevent.cpp would help fix the bug in this code: https://github.com/RPG-18/rabbitmq-cpp-tutorials/pull/1/commits/5ea4ff1dc27f13a4fd2cc01659ff49561eff79e5
I've replaced the AMQP-CPP files with the newest versions but I still get the same error.
That is because this code has a bug in how it reads or writes to the socket. I suggested the libevent handler example because presumably that does not have the same bug as the one that uses the Poco network classes.
The screenshot proves that your RabbitMQ environment is working correctly because your Java program is working correctly.
At this point I no longer have the time to provide free assistance. If my time allows, I may try to get this code running on my Linux workstation to debug further, but I can't make any guarantees.