2018 RabbitMQ(1)Install 3.x On CentOS7 and Java Clients
Read Old blogs to understand the structure.
Install ErLang on CentOS7
Download the latest source code
> wget http://erlang.org/download/otp_src_20.3.tar.gz
Unzip and go to that directory
> export LANG=C
> ./configure --prefix=/usr/erlang
Exception:
configure: error: no acceptable C compiler found in $PATH
Solution:
https://stackoverflow.com/questions/19816275/no-acceptable-c-compiler-found-in-path-when-installing-python
> sudo yum groupinstall "Development tools"
Exception:
configure: error: No curses library functions found
configure: error: /bin/sh '/home/carl/install/otp_src_20.3/erts/configure' failed for erts
Solution:
http://docs.basho.com/riak/1.3.0/tutorials/installation/Installing-Erlang/
Try add more dependency
> sudo yum install gcc glibc-devel make ncurses-devel openssl-devel autoconf
It solve the issue, but We need more to have more features I think
*********************************************************************
********************** APPLICATIONS DISABLED **********************
*********************************************************************
jinterface : No Java compiler found
odbc : ODBC library - link check failed
*********************************************************************
*********************************************************************
********************** APPLICATIONS INFORMATION *******************
*********************************************************************
wx : wxWidgets not found, wx will NOT be usable
*********************************************************************
*********************************************************************
********************** DOCUMENTATION INFORMATION ******************
*********************************************************************
documentation :
xsltproc is missing.
fop is missing.
The documentation can not be built.
*********************************************************************
Solution:
Install Java OpenJDK
> sudo yum install java-1.8.0-openjdk-devel
> java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
Install ODBC
http://asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/installing_configuring_odbc.html
> sudo yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel
Install wxWidget
https://www.wxwidgets.org/downloads/
https://wiki.wxwidgets.org/Install
https://stackoverflow.com/questions/24776745/erlang-build-fails-can-not-link-the-wx-driver-wx-will-not-be-useable
Ignore this for now
Install fop
> sudo yum install fop
Configure again
> ./configure --prefix=/usr/erlang --without-wx
> make
> sudo make install
> sudo ln -s /usr/erlang/bin/erl /usr/bin/erl
> erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V9.3 (abort with ^G)
1>
Install RabbitMQ Version 3.7.4
Download the generic package from here https://www.rabbitmq.com/install-generic-unix.html
>tar xvfJ rabbitmq-server-generic-unix-3.7.4.tar.xz
>mv rabbitmq_server-3.7.4 ~/tool/rabbitmq-3.7.4
> sudo ln -s /home/carl/tool/rabbitmq-3.7.4 /opt/rabbitmq-3.7.4
> sudo ln -s /opt/rabbitmq-3.7.4 /opt/rabbitmq
Start the Server and Check the Service
> sudo sbin/rabbitmq-server
> sudo sbin/rabbitmqctl status
Examples in JAVA
Check RabbitMQ Port numbers
> sudo yum install net-tools
> netstat -lntu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp6 0 0 :::5672 :::* LISTEN
tcp6 0 0 :::4369 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
udp 0 0 0.0.0.0:18926 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 127.0.0.1:323 0.0.0.0:*
udp6 0 0 :::44958 :::*
udp6 0 0 ::1:323 :::*
Default port is 5672
4369 Erlang clustering
5672 main port
It is my virtualBox machine, so I disable the firewall first
> sudo systemctl status firewalld
> sudo systemctl stop firewalld
> sudo systemctl disable firewalld
I also set the RabbitMQ binding to
> echo $RABBITMQ_NODE_IP_ADDRESS
0.0.0.0
The Old documents are too old from http://sillycat.iteye.com/blog/1575314
But I upgrade the source codes for easytalker
https://www.rabbitmq.com/tutorials/tutorial-one-java.html
List Queues
> sudo sbin/rabbitmqctl list_queues
Timeout: 60.0 seconds ...
Listing queues for vhost / ...
Exception with my Simple Hello World
148 [AMQP Connection 192.168.56.102:5672] WARN com.rabbitmq.client.impl.ForgivingExceptionHandler - An unexpected connection driver error occured (Exception message: Connection reset)
Exception in thread "main" com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:362)
Check the Installation steps
https://www.rabbitmq.com/install-generic-unix.html
https://www.rabbitmq.com/management.html
List Users
> sudo sbin/rabbitmqctl list_users
guest [administrator]
Add Users
> sudo sbin/rabbitmqctl add_user carl test
> sudo sbin/rabbitmqctl set_user_tags carl administrator
> sudo sbin/rabbitmqctl set_permissions -p / carl ".*" ".*" ".*"
com.rabbitmq
amqp-client
5.2.0
Java Codes
package com.sillycat.easytalker.plugins.rabbitmq.hello;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
public class TestProducer {
private final static String QUEUE_NAME = "hello";
private final static String SERVER_HOST = "centos-dev1";
public static void main(String[] args) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(SERVER_HOST);
factory.setUsername("carl");
factory.setPassword("kaishi");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World! Sillycat!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
}
}
package com.sillycat.easytalker.plugins.rabbitmq.hello;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Consumer;
import com.rabbitmq.client.ConsumerCancelledException;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.ShutdownSignalException;
public class TestConsumer {
private final static String QUEUE_NAME = "hello";
private final static String SERVER_HOST = "centos-dev1";
public static void main(String[] args) throws IOException, ShutdownSignalException, ConsumerCancelledException,
InterruptedException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(SERVER_HOST);
factory.setUsername("carl");
factory.setPassword("kaishi");
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) {
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);
}
}
References:
RabbitMQ History Blog
http://sillycat.iteye.com/blog/1565771
http://sillycat.iteye.com/blog/1567052
http://sillycat.iteye.com/blog/1575002
http://sillycat.iteye.com/blog/1575314
http://sillycat.iteye.com/blog/1575816
http://sillycat.iteye.com/blog/1578635
http://sillycat.iteye.com/blog/1579464
http://sillycat.iteye.com/blog/1582971
http://sillycat.iteye.com/blog/2037218
http://sillycat.iteye.com/blog/2066116
http://sillycat.iteye.com/blog/2183555
https://stackoverflow.com/questions/26811924/spring-amqp-rabbitmq-3-3-5-access-refused-login-was-refused-using-authentica/26820152