RabbitMQ(9)Have Working Queue on MAC with Scala in Cluster Mode
1. Install on my MAC laptop.
>su root
>port selfupdate
>sudo port install erlang +ssl
Download the source from URL
http://www.rabbitmq.com/releases/rabbitmq-server/v3.1.5/rabbitmq-server-generic-unix-3.1.5.tar.gz
>tar zxvf rabbitmq-server-generic-unix-3.1.5.tar.gz
>mv rabbitmq_server-3.1.5 /Users/carl/tool/
>sudo ln -s /Users/carl/tool/rabbitmq_server-3.1.5 /opt/rabbitmq-3.1.5
>sudo ln -s /opt/rabbitmq-3.1.5 /opt/rabbitmq
Start the Server
>sudo sbin/rabbitmq-server
Check and Stop the Server
>sudo sbin/rabbitmqctl status
>sudo sbin/rabbitmqctl stop
>sudo vi ~/.profile
export PATH=/opt/rabbitmq/sbin:$PATH
>. ~/.profile
2. Example of Producer and Consumer
The sample project is in super duty .
Here is how we build the connection
package com.sillycat.superduty.service
import com.rabbitmq.client.ConnectionFactory
import com.rabbitmq.client.QueueingConsumer
object RabbitMQConnectionService {
val TASK_QUEUE_NAME = "task_queue"
val SERVER_HOST = "localhost"
def connect = {
val factory = new ConnectionFactory
factory.setHost(SERVER_HOST)
val conn = factory.newConnection()
val channel = conn.createChannel()
val durable = true
channel.queueDeclare(TASK_QUEUE_NAME, durable, false, false, null)
val prefetchCount = 1
channel.basicQos(prefetchCount)
val consumer = new QueueingConsumer(channel)
val autoAck = false
channel.basicConsume(TASK_QUEUE_NAME, autoAck, consumer)
(conn, channel, consumer)
}
}
Here is the Producer
package com.sillycat.superduty.jobs.producer
import com.sillycat.superduty.service.RabbitMQConnectionService
import com.rabbitmq.client.MessageProperties
object NewTaskRabbitMQ extends App {
val (conn, channel, consumer) = RabbitMQConnectionService.connect
val message = "campaign"
Range(1, 10, 1).foreach { num =>
channel.basicPublish("", RabbitMQConnectionService.TASK_QUEUE_NAME,
MessageProperties.PERSISTENT_TEXT_PLAIN, (message + num).getBytes());
}
channel.close
conn.close
}
Here is the Consumer
package com.sillycat.superduty.jobs.consumer
import com.sillycat.superduty.service.RabbitMQConnectionService
import com.rabbitmq.client.QueueingConsumer
import com.typesafe.scalalogging.slf4j.Logging
object WorkerRabbitMQ extends App with Logging {
val (conn, channel, consumer) = RabbitMQConnectionService.connect
while (true) {
val delivery: QueueingConsumer.Delivery = consumer.nextDelivery()
val message = new String(delivery.getBody())
val deliverTag = delivery.getEnvelope.getDeliveryTag
logger.debug("Worker get task=" + message + " delivery tag=" + deliverTag)
channel.basicAck(deliverTag, false)
}
}
Here is how we execute the command
>sudo sbin/rabbitmq-server
>sbt 'run-main com.sillycat.superduty.jobs.consumer.WorkerRabbitMQ'
>sbt 'run-main com.sillycat.superduty.jobs.consumer.WorkerRabbitMQ'
>sbt 'run-main com.sillycat.superduty.jobs.producer.NewTaskRabbitMQ'
And the build.sbt should add these dependencies.
"com.rabbitmq" % "amqp-client" % "3.1.4"
3. Cluster Configuration
Should always follow this document
http://www.rabbitmq.com/clustering.html
>chmod 777 ~/.erlang.cookie
change the content of the file if you need
>chmod 400 ~/.erlang.cookie
>sudo chown -R carl ~/.erlang.cookie
>sudo chgrp -R staff ~/.erlang.cookie
Enable the web UI management
>rabbitmq-plugins enable rabbitmq_management
Start cluster on single machine
>RABBITMQ_NODE_PORT=5672 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15672}]" RABBITMQ_NODENAME=rabbit1 sbin/rabbitmq-server -detached
>RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}]" RABBITMQ_NODENAME=rabbit2 sbin/rabbitmq-server -detached
Check status of node1
>rabbitmqctl -n rabbit1 cluster_status
Cluster status of node rabbit1@sparkworker1 ...
[{nodes,[{disc,[rabbit1@sparkworker1]}]},
{running_nodes,[rabbit1@sparkworker1]},
{partitions,[]}]
…done.
>rabbitmqctl -n rabbit2 cluster_status
Cluster status of node rabbit2@sparkworker1 ...
[{nodes,[{disc,[rabbit2@sparkworker1]}]},
{running_nodes,[rabbit2@sparkworker1]},
{partitions,[]}]
...done.
Stop the second node and make it join the first cluster
>rabbitmqctl -n rabbit2 stop_app
>rabbitmqctl -n rabbit2 join_cluster rabbit1@sparkworker1
>rabbitmqctl -n rabbit2 start_app
Check the status again
>rabbitmqctl -n rabbit1 cluster_status
Cluster status of node rabbit1@sparkworker1 ...
[{nodes,[{disc,[rabbit1@sparkworker1,rabbit2@sparkworker1]}]},
{running_nodes,[rabbit2@sparkworker1,rabbit1@sparkworker1]},
{partitions,[]}]
...done.
Visit the page
http://localhost:15672/
The default username and password should be guest/guest.
Changing the node Type
>rabbitmqctl -n rabbit2 stop_app
>rabbitmqctl -n rabbit2 change_cluster_node_type ram
>rabbitmqctl -n rabbit2 start_app
or
>rabbitmqctl -n rabbit1 stop_app
>rabbitmqctl -n rabbit1 change_cluster_node_type disc
>rabbitmqctl -n rabbit1 start_app
The client will be something like this if connect to cluster
val factory = new ConnectionFactory
//factory.setHost(SERVER_HOST)
//val conn = factory.newConnection()
val addrArr = Array(new Address("localhost", 5672), new Address("", 5673))
val conn = factory.newConnection(addrArr)
The source codes here is like this:
for (Address addr : addrs) {
try {
FrameHandler frameHandler = createFrameHandler(addr);
AMQConnection conn =
new AMQConnection(username,
password,
frameHandler,
executor,
virtualHost,
getClientProperties(),
requestedFrameMax,
requestedChannelMax,
requestedHeartbeat,
saslConfig);
conn.start();
return conn;
} catch (IOException e) {
lastException = e;
}
}
So, there is no load balance and we will try to get connection one by one till we get one, it is not good. We can consider put ha-proxy or nginx before that.
Break a Cluster
>rabbitmqctl -n rabbit2 stop_app
>rabbitmqctl -n rabbit2 reset
References:
RabbitMQ 1 ~ 8
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
https://github.com/koeninger/rabbit-example
http://www.rabbitmq.com/install-macports.html
http://www.rabbitmq.com/getstarted.html
Message Working Queue
http://sillycat.iteye.com/blog/1575314
https://github.com/koeninger/rabbit-example
Cluster
http://www.rabbitmq.com/clustering.html
http://www.rabbitmq.com/partitions.html
http://www.rabbitmq.com/nettick.html
management page
http://www.rabbitmq.com/management.html
All the Client
http://www.rabbitmq.com/devtools.html
Tips
http://fengchangjian.com/?p=1896
- 浏览: 2551874 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
发表评论
-
Update Site will come soon
2021-06-02 04:10 1678I am still keep notes my tech n ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 294Hadoop Docker 2019 Version 3.2. ... -
Nginx and Proxy 2019(1)Nginx Enable Lua and Parse JSON
2019-12-03 04:17 449Nginx and Proxy 2019(1)Nginx En ... -
Data Solution 2019(13)Docker Zeppelin Notebook and Memory Configuration
2019-11-09 07:15 294Data Solution 2019(13)Docker Ze ... -
Data Solution 2019(10)Spark Cluster Solution with Zeppelin
2019-10-29 08:37 248Data Solution 2019(10)Spark Clu ... -
AMAZON Kinesis Firehose 2019(1)Firehose Buffer to S3
2019-10-01 10:15 322AMAZON Kinesis Firehose 2019(1) ... -
Rancher and k8s 2019(3)Clean Installation on CentOS7
2019-09-19 23:25 313Rancher and k8s 2019(3)Clean In ... -
Pacemaker 2019(1)Introduction and Installation on CentOS7
2019-09-11 05:48 343Pacemaker 2019(1)Introduction a ... -
Crontab-UI installation and Introduction
2019-08-30 05:54 455Crontab-UI installation and Int ... -
Spiderkeeper 2019(1)Installation and Introduction
2019-08-29 06:49 510Spiderkeeper 2019(1)Installatio ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 370Supervisor 2019(2)Ubuntu and Mu ... -
Supervisor 2019(1)CentOS 7
2019-08-19 09:33 331Supervisor 2019(1)CentOS 7 Ins ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 373Redis Cluster 2019(3)Redis Clus ... -
Amazon Lambda and Version Limit
2019-08-02 01:42 438Amazon Lambda and Version Limit ... -
MySQL HA Solution 2019(1)Master Slave on MySQL 5.7
2019-07-27 22:26 530MySQL HA Solution 2019(1)Master ... -
RabbitMQ Cluster 2019(2)Cluster HA and Proxy
2019-07-11 12:41 464RabbitMQ Cluster 2019(2)Cluster ... -
Running Zeppelin with Nginx Authentication
2019-05-25 21:35 323Running Zeppelin with Nginx Aut ... -
Running Zeppelin with Nginx Authentication
2019-05-25 21:34 324Running Zeppelin with Nginx Aut ... -
ElasticSearch(3)Version Upgrade and Cluster
2019-05-20 05:00 329ElasticSearch(3)Version Upgrade ... -
Jetty Server and Cookie Domain Name
2019-04-28 23:59 404Jetty Server and Cookie Domain ...
相关推荐
rabbitmq-转储队列 将消息从 RabbitMQ 队列转储到文件,而不影响队列。 安装 下载一个版本 可以在页面上找到预编译的二进制包。 从源代码编译 如果您安装了 ,则可以通过运行以下命令从源代码安装 rabbitmq-dump-...
RabbitMQ 的 Backing Queue 结构 RabbitMQ 的 Backing Queue 结構是一個复杂的消息队列系统,分为 Exchange 和 MQ 两部分。Exchange 类似于路由器,根据自身类型和 binding 信息决定消息的去向,而 MQ 负责暂时存储...
RabbitMQ作为一款广泛使用的开源消息代理,是实现工作队列(Work Queue)模式的理想选择。本文将深入探讨RabbitMQ工作队列的实现,包括消息确认机制、消息持久化以及公平调度等关键知识点。 首先,让我们理解工作...
don’t have a working setup with Python and RabbitMQ, or you’d just like to experi- ment without setting up the whole environment, we’ve included instructions on set- ting up a Vagrant box with ...
Writing this book has been like discovering RabbitMQ itself—encountering a prob- lem that needed solving, but not knowing what the solution looked like. Until May 2010, we didn’t even know each ...
RabbitMQ is an efficient, highly scalable, and easy-to-deploy queue that makes handling this message traffic virtually effortless. Offered under an open source license and language neutral, RabbitMQ ...
这个压缩包“rabbitmq-server-mac-standalone-3.5.7.tar.gz”是专为MAC OS X操作系统设计的RabbitMQ服务器版本,支持10.6.4或更高版本。在本文中,我们将深入探讨RabbitMQ的核心概念、安装过程以及如何在MAC OS X上...
理解Confirm消息确认机制 消息的确认,是指生产者投递消息后,如果Broker收到消息,则会给我们生产者一个应答。生产者进行接收应答,用来确定这条消息是否正常的发送到Broker,...import com.rabbitmq.client.Queuein
RabbitMQ 集群是将多个RabbitMQ节点组织成一个逻辑单元,它们共同分享并管理用户、虚拟主机、队列、交换机、绑定、运行时参数等分布式状态。集群化提供了高可用性,当单个节点故障时,其他节点能够接管服务,确保...
RabbitMQ 3.6.12 is a maintenance release. Upgrades and Compatibility See the "Upgrading clusters" section of the ...To upgrade a RabbitMQ cluster, follow the instructions in RabbitMQ documentation.
### RabbitMQ in Action 高清版 - 分布式消息传递为所有人 #### 一、书籍简介与背景 《RabbitMQ in Action》是一本全面介绍RabbitMQ分布式消息队列系统的书籍,由Alvaro Videla和Jason J. W. Williams共同撰写,...
docker-rabbitmq-cluster集群搭建docker-rabbitmq-cluster集群搭建
laravel-queue-rabbitmq, 用于 Laravel 队列的RabbitMQ驱动程序 用于 Laravel的 RabbitMQ队列驱动程序 安装通过 Composer 安装这里软件包,使用:composer require vladimir-yuldashev/laravel-queue-
RabbitMQ in depth的内容覆盖了从RabbitMQ的基础知识到深层次的应用,适合作为中级水平的读者使用,特别是那些正在编写使用RabbitMQ的应用程序,或者是在生产环境中负责管理RabbitMQ的开发者或系统管理员。...
在RabbitMQ中,代理(或称Exchange)配置和编码是消息传递的核心组成部分。RabbitMQ是一个开源的消息队列系统,它使用代理来路由消息到正确的队列,从而实现不同应用之间的异步通信。以下是对标题和描述中提到的知识...
**RabbitMQ for Mac 安装指南** RabbitMQ 是一个开源的消息代理和队列服务器,广泛用于微服务架构中的消息传递。它基于AMQP(Advanced Message Queuing Protocol)协议,提供高可用性、可靠性和可扩展性。在这个...
### RabbitMQ 集群环境搭建知识点 #### 一、RabbitMQ集群环境搭建概述 在分布式系统中,为了提高消息处理能力与系统的可靠性,通常会采用RabbitMQ集群架构。RabbitMQ集群允许消息发布者将消息发送到任意一个集群...
k8s部署rabbitmq-cluster集群配置文件和docker镜像文件,配合文章学习用,有需要可以下载,无需修改直接部署即可
cluster是由多个运行RabbitMQ的Erlang节点组成,它们之间共享队列(queue)、交换机(exchange)和绑定(binding)等元数据信息。 元数据是关于数据的数据,在RabbitMQ中,主要分为Queue元数据、Exchange元数据、...