《Mastering RabbitMQ》_笔记


基于《Mastering RabbitMQ》
消息中间件:消息路由与确认机制,消息备份与持久化。

1,Getting Started

消息队列,队列结构,先进先出FIFO。
队列类型:普通队列,镜像队列,独占队列。
rabbitmqctl命令:

  • stop、shutdown;关闭rabbitmq和erlang虚拟机。
  • stop_app、start_app;关闭、启动rabbitmq
  • reset;重置rabbitmq数据
  • status;状态

producer–connection(channel)–vhost–exchange–binding–queue–connection(channel)–consumer

2,Configuring Rabbitmq

环境变量、配置文件、运行时参数
配置文件位置

  • linux:/etc/rabbitmq/rabbitmq.config
  • window:~/etc/rabbitmq.config

环境变量

定义节点名,文件夹路径,ip和port,erlang虚拟机参数。
linux,RABBITMQ_CONF_ENV_FILE/rabbitmq-env.conf;默认为/etc/rabbitmq,echo查看,export设置。
window,直接设置环境变量,或者修改rabbitmq-env.bat。
除rabbitmq-defaults.bat外,其余bat脚本都调用rabbitmq-env.bat。

作用linux默;设置时不带rabbitmq_前缀window默;BASE指代%RABBITMQ_BASE%
rabbitmq_nodename节点名rabbit@hostnamerabbit@%COMPUTERNAME%
rabbitmq_base日志、数据位置%APPDATA%/RabbitMQ
rabbitmq_config_file配置文件/etc/rabbitmq/rabbitmq.confBASE/rabbitmq.conf
rabbitmq_log_base日志全路径名/var/log/rabbitmqBASE/log
rabbitmq_mnesia_base数据库文件目录/var/lib/rabbitmq/mnesiaBASE/db
rabbitmq_plugins_dir插件目录~/pluginsBASE/plugins
rabbitmq_node_ip_address绑定的ip0.0.0.00.0.0.0
rabbitmq_node_port绑定的端口56725672

配置文件

linux:/etc/rabbitmq;
window:%APPDATA%/RabbitMQ
由rabbitmq.conf、advanced.conf组成。配置网络、安全、存储、队列等。
3.7.0以前,为rabbitmq.config类型,数组[],注释用%%;
3.7.0及以后,可用rabbitmq.conf类型,key=value,注释用#。

  • auth_mechanisms;SASL安全验证机制,[‘PLAIN’, ‘AMQPLAIN’]
  • default_user;用户名,guest
  • default_pass;密码,guest
  • default_permission;默认vhost的配置、读、写权限,[".", ".", “.*”]
  • disk_free_limit;磁盘最少剩余量,低时报警。50M
  • heartbeat;心跳间隔,s。60默,0禁用
  • hipe_compile;HIPE高效编译,false
  • log_levels;日志级别,[{connection, info}]默。
    事件类别:channel、connection、federation、mirroring;
    日志级别:error、warn、info、debug、none
  • tcp_listeners;监听端口地址,[5672]
  • ssl_listeners;ssl连接端口地址,同上,[]
  • vm_memory_high_watermark;流程控制阈值,0.4

运行时参数

运行时修改环境变量、配置文件参数值。
先list查看,后修改。
rabbitmqctl命令,set_、clear_、list_前缀:

  • set_parameter,clear_parameter,list_parameters;设置、清除、展示参数
  • set_policy,cluear_policy,list_policies;策略,queue和exchange在集群中的行为
  • set_vm_memory_high_watermark;设置流程控制阈值

3,Architecture and Messaging

消息中间件作用:

  • 解耦。代码解耦用依赖注入,结构解耦用消息中间件。
  • 整合多平台。提供统一的消息格式。
  • 解决可扩展性。消息中间件高吞吐量、低延时、高并发,可有效充当中间者。事件驱动。

信息收发相关结构:

  • Message Oriented Middleware Architecture;消息中间件结构,producer-broker-consumer。解决系统整合、系统间通信问题。
  • Event Driven Architecture;事件驱动结构,异步;基于消息推送,push。event producer-event manager-event consumer(监听器)。解决扩展性,高可用。

4,Clustering and High Availability

Federation级联

多个rabbitmq实例间传输message。

  • rabbitmq-plugins enable rabbitmq_federation;开启级联
  • rabbitmq-plugins enable rabbitmq_federation_management;开启管理

三级配置:upstreams上游、upstream sets一组上游、policies交换器匹配策略。
类似主从。下游从上游upstream取消息。

集群

集群间共享元数据;去中心化。
集群节点分两类:ram(元数据存于内存),disk(元数据存于内存和磁盘)
集群中至少要一个disk节点,否则不能修改元数据。
启动rabbitmq时设置节点类型,默认为disk节点。
创建集群
rabbitmqctl stop_app;
rabbitmqctl join_cluster NAME;加入集群重启后,会自动加入集群

  • status获取NAME;
  • host文件添加映射;
  • 复制.erlang.cookie文件。window中为C:\Windows\System32\config\systemprofile、C:\Users\Administrator。文件值经hash计算后作为cookie值。

rabbitmqctl start_app;
rabbitmqctl cluster_status;查看集群状态
rabbitmqctl change_cluster_node_type ram/disk;修改集群节点类型
rabbitmqctl forget_cluster_node NAME;移除集群节点
window下运行多个rabbitmq
设置临时节点名、tcp端口、配置文件路径;而后启动rabbitmq-server。
配置文件路径不允许有空格。
配置文件rabbit5673.conf;内容:management.tcp.port = 15673
使用默认配置文件,且不使用web控制台,可不配配置文件路径。
启动脚本:

set RABBITMQ_NODE_PORT=5673
echo %RABBITMQ_NODE_PORT%
set RABBITMQ_NODENAME=rabbit%RABBITMQ_NODE_PORT%
echo %RABBITMQ_NODENAME%
set RABBITMQ_CONFIG_FILE=D:\workSoftWare\rabbitmq\rabbitmq_server-3.7.11\sbin\%RABBITMQ_NODENAME%
echo %RABBITMQ_CONFIG_FILE%
rabbitmq-server -detached

高可用

keepalived等tcp负载均衡工具。

5,Plugins and Plugin Development

插件是软件扩展的主要方式。

插件管理和默认插件

rubbitmq-plugins enable/disable通过修改插件配置,并通知server,开启/禁用插件。
rubbitmq-plugins,-n指定节点名:

  • help;命令详情
  • list;列出插件。-v详情,-e所有开启的插件
  • enable/disable NAMES;开启、禁用,逗号隔开

安装第三方插件:

  • 下载插件,make制作.ez格式插件包;放到~/plugins目录。window安装make命令
  • rabbitmq-plugins enable Name;开启插件

插件配置参数:

  • rabbitmq_plugins_dir;插件目录,$RABBITMQ_HOME/plugins
  • rabbitmq_plugins_expand_dir;扩展目录。$RABBITMQ_MNESIA_BASE/$RABBITMQ_NODENAMEplugins-expand

6,Managing Your RabbitMQ Server

用户管理,vhost体系管理,收发消息
方式:rabbitmqctl、web控制台、rest API

命令行管理

rabbitmqctl CMD ARGS;命令格式
rabbitmqctl help CMD;命令详情
rabbitmqctl help > help;将命令详情存入本地文件,便于查看
集群命令
join_cluster;加入集群
forget_cluster_node;移除节点
change_cluster_node_type;修改节点类型,dist、ram
update_cluster_nodes;更新节点信息
cluster_status;集群状态
用户命令
add_user,delete_user;增删用户
change_password,clear_password;修改密码,清除密码
set_user_tags;设置角色
list_users;列出所有用户
vhost及权限命令
vhost,权限的最小粒度;一个节点多个vhost,满足多租户。
权限类型:configure、read、write
add_vhost,delete_vhost,list_vhosts;增删,列出所有vhost
set_permissions,clear_permissions;设置权限,清除权限
list_permissions,list_user_permissions;列出所有用户,指定用户权限
其他命令
set_parameter,clear_parameter,list_parameters;vhost参数
set_policy,clear_policy,list_policies;策略
list_queues,list_bindings,list_exchanges;列出队列、绑定、交换器
list_connections,list_channels,list_consumers;列出连接、通道、消费者
status,report;节点状态,节点报告(包含状态)
environment;应用的环境变量
close_connection;关闭连接
trace_on,trace_off;开启,关闭虚拟机
start_app,stop_app;开启,关闭rabbitmq
stop、shutdown;关闭rabbitmq、erlang虚拟机。
reset;重置rabbitmq,会清空集群连接信息。
set_vm_memory_high_water;内存阈值

web控制台

可管理user/permission、vhost、exchange、binding、queue、connection;可视化监控;收发消息。
rabbitmq-plugins enable rabbitmq_management;开启web控制台,需重启erlang
port–15672,guest:guest
控制台查看消息内容,不会消费消息。只能查看队首消息。

个人

配置:环境变量(临时,env脚本)、配置文件(默认,env脚本指定)、实时参数
组件:rabbitmq-service,rabbitmqctl,rabbitmq-plugins
集群:类似es,主从队列;集群节点元数据相同;转发方式获取队列消息
exchange类型:head,direct、topic,fanout;消息发布
队列类型:

  • 内存队列,持久化队列
  • 普通队列,镜像队列,独占队列

消息分发策略:发布订阅(多次消费)、轮询分发(推),公平分发(权重,推),重发,消息拉取
队列匹配:直接,topic

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Master the art of developing message-based applications with RabbitMQ, About This Book, Learn how to administer, manage, and extend your own message broker, RabbitMQDevelop clients to make a message bridge between your software systems using RabbitMQDiscover how to achieve proficiency with RabbitMQ with the well-defined descriptions of the topics, Who This Book Is For, If you are an intermediate-level RabbitMQ developer, who wants to achieve professional-level expertise in the subject, this book is for you. You'll also need to have a decent understanding of message queuing., What You Will Learn, Administer RabbitMQ using different toolsUnderstand the roots and details of messaging, message brokers, and AMQP protocolScale the RabbitMQ server using the clusters and high availability techniquesExtend RabbitMQ by developing the Erlang OTP-based applications that use the RabbitMQ APIManage the RabbitMQ server using its powerful toolsMonitor the RabbitMQ Server using different open source tools such as Nagios, Munin, and ZabbixEnsure your RabbitMQ's security using SSL, SASL, and access controlDevelop RabbitMQ clients using Java, Python, and C# with an industry example, In Detail, RabbitMQ is one of the most powerful Open Source message broker software, which is widely used in tech companies such as Mozilla, VMware, Google, AT&T, and so on. RabbitMQ gives you lots of fantastic and easy-to-manage functionalities to control and manage the messaging facility with lots of community support. As scalability is one of our major modern problems, messaging with RabbitMQ is the main part of the solution to this problem., This book explains and demonstrates the RabbitMQ server in a detailed way. It provides you with lots of real-world examples and advanced solutions to tackle the scalability issues., You'll begin your journey with the installation and configuration of the RabbitMQ server, while also being given specific details pertaining to the subject. Next, you'll study the major problems that our server faces, including scalability and high availability, and try to get the solutions for both of these issues by using the RabbitMQ mechanisms. Following on from this, you'll get to design and develop your own plugins using the Erlang language and RabbitMQ's internal API. This knowledge will help you to start with the management and monitoring of the messages, tools, and applications. You'll also gain an understanding of the security and integrity of the messaging facilities that RabbitMQ provides. In the last few chapters, you will build and keep track of your clients (senders and receivers) using Java, Python, and C#., Style and approach, An easy-to-follow guide, full of hands-on examples based around managing, monitoring, extending, and securing RabbitMQ and its internal tools. You will learn how to develop your own clients using Java, Python, and C#.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值