linux安装rabbitmq ssm集成rabbitmq

rabbitmq 3.8.0 & erlang 22.1 源码编译安装

摘自 https://www.cnblogs.com/amosli/p/11765483.html

1.安装erlang编译依赖

sudo yum install -y gcc gcc-c++ glibc-devel make ncurses-devel openssl-devel autoconf java-1.8.0-openjdk-devel git

1.2.下载erlang22.1源码包
wget http://erlang.org/download/otp_src_22.1.tar.gz

1.3 编译并安装
# 解压
tar -zvxf otp_src_22.1.tar.gz
cd otp_src_22.1

#编译&安装
./otp_build autoconf
./configure && make && sudo make install
1.4.验证

erl -version
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 10.5
或

erl
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [hipe]

Eshell V10.5 (abort with ^G)
1>

2.rabbitmq3.8.0 binary安装

2.1.下载rabbitmq安装包
wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.8.0/rabbitmq-server-generic-unix-3.8.0.tar.xz

2.2.解压并配置环境变量

解压:
xz -d rabbitmq-server-generic-unix-3.8.0.tar.xz
tar -xvf rabbitmq-server-generic-unix-3.8.0.tar
mv rabbitmq_server-3.8.0 /usr/local/rabbitmq_server-3.8.0

配置环境变量:
vim /etc/profile
# 在最后一行添加如下命令
export PATH=$PATH:/usr/local/lib/erlang/bin:/usr/local/rabbitmq_server-3.8.0/sbin
source /etc/profile

2.3.启动rabbitmq
rabbitmq-plugins enable rabbitmq_management
rabbitmq-server 或 rabbitmq-server -detached(后台运行)
2.4.添加新用户

默认账号密码是(guest/guest)这里新添加账号:admin/admin
rabbitmqctl add_user admin admin
rabbitmqctl set_user_tags admin administrator

2.5停止rabbitmq
rabbitmqctl shutdown

2.6.修改核心配置参数

rabbitmq的核心配置参数在/usr/local/rabbitmq_server-3.8.0/ebin/rabbit.app里

vim /usr/local/rabbitmq_server-3.8.0/ebin/rabbit.app
# 找到loopback_users 修改为如下内容(去除 <<"guest">>中<<"">>) {loopback_users, [guest]},

修改完毕后就能解除guest账户的本地登录限制了。

ssm集成rabbitmq

摘自:https://blog.csdn.net/qq_30764991/article/details/80241205

rabbitmq管理地址:http://127.0.0.1:15672/

 ssm配置

pom.xml

<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.0.0</version>
</dependency>

<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.7.2.RELEASE</version>
</dependency>


applicationContext-rabbitmq.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.6.xsd">



<!-- rabbitmq连接配置 -->
<!-- virtual-host 就是在(1)中配置的VH-->
<!-- -->
<!-- -->
<rabbit:connection-factory id="connectionFactory" virtual-host="test"
host="192.168.1.49" username="admin" password="admin"
port="5672" />
<rabbit:admin connection-factory="connectionFactory" />


<!-- 声明消息队列,消息系统监听队列 -->
<!-- messageQueue 是在(1)中创建的队列 -->
<rabbit:queue id="messageQueue" durable="true"
auto-delete="false" exclusive="false" name="messageQueue" />
<rabbit:queue id="messageQueue" durable="true"
auto-delete="false" exclusive="false" name="messageQueue1" />
<rabbit:queue id="messageQueue" durable="true"
auto-delete="false" exclusive="false" name="messageQueue2" />


<!-- exchange queue binging key 绑定 -->
<!--声明交换 在(1)配置的交换-->
<rabbit:topic-exchange name="messageExchange"
durable="true" auto-delete="false" id="messageExchange">
<rabbit:bindings>
<!-- 声明队列和交换的关系 -->
<rabbit:binding pattern="message.*" queue="messageQueue"></rabbit:binding>
<rabbit:binding pattern="message.*" queue="messageQueue1"></rabbit:binding>
<rabbit:binding pattern="message.*" queue="messageQueue2"></rabbit:binding>
</rabbit:bindings>
</rabbit:topic-exchange>


<rabbit:template exchange="messageExchange" id="rabbitTemplate"
connection-factory="connectionFactory" />


<rabbit:listener-container
connection-factory="connectionFactory" acknowledge="auto">
<!-- 让消费者监听这个队列 -->
<rabbit:listener ref="messageConsumer" queues="messageQueue" />
<rabbit:listener ref="messageConsumer1" queues="messageQueue1" />
<rabbit:listener ref="messageConsumer2" queues="messageQueue2" />
</rabbit:listener-container>
<!--声明生产者 -->
<bean id="messageSender" class="com.shop.mq.MessageSender">
<property name="amqpTemplate" ref="rabbitTemplate"></property>
<!-- <property name="routingKey" value="message.test" ></property> -->
</bean>
<!--声明消费者 -->
<bean id="messageConsumer" class="com.shop.mq.MessageConsumer" />

<!--声明生产者 -->
<bean id="messageSender1" class="com.shop.mq.MessageSender1">
<property name="amqpTemplate" ref="rabbitTemplate"></property>
<!-- <property name="routingKey" value="message.test" ></property> -->
</bean>
<!--声明消费者 -->
<bean id="messageConsumer1" class="com.shop.mq.MessageConsumer1" />

<!--声明生产者 -->
<bean id="messageSender2" class="com.shop.mq.MessageSender2">
<property name="amqpTemplate" ref="rabbitTemplate"></property>
<!-- <property name="routingKey" value="message.test" ></property> -->
</bean>
<!--声明消费者 -->
<bean id="messageConsumer2" class="com.shop.mq.MessageConsumer2" />


</beans>

生产者MessageSender

package com.shop.mq;


import org.springframework.amqp.core.AmqpTemplate;


public class MessageSender {

private AmqpTemplate amqpTemplate;

private String routingKey;

public AmqpTemplate getAmqpTemplate() {
return amqpTemplate;
}

public void setAmqpTemplate(AmqpTemplate amqpTemplate) {
this.amqpTemplate = amqpTemplate;
}

public String getRoutingKey() {
return routingKey;
}

public void setRoutingKey(String routingKey) {
this.routingKey = routingKey;
}

public void sendDataToQueue(Object obj) {

amqpTemplate.convertAndSend(this.routingKey, obj);
}

}


消费者MessageConsumer 

package com.shop.mq;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

public class MessageConsumer implements MessageListener{

private Logger logger = LoggerFactory.getLogger(MessageConsumer.class);
@Override
public void onMessage(Message message) {
// createOrder();
logger.info("receive message:{}",message);
}

}


Controller

package com.shop.controller.test;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.shop.mq.MessageSender;
import com.shop.mq.MessageSender1;
import com.shop.mq.MessageSender2;



@Controller
@RequestMapping("/rabbit")
public class MainController {

// 注入消息生产者
@Autowired
private MessageSender messageSender;
// 注入消息生产者
@Autowired
private MessageSender1 messageSender1;
// 注入消息生产者
@Autowired
private MessageSender2 messageSender2;

private Logger logger = LoggerFactory.getLogger(MessageSender.class);

@RequestMapping(value = "/main")
public String main() {
return "main";
}

@RequestMapping(value = "/doValid")
@ResponseBody
public String doValid() {

// 设置RoutingKey,匹配message.*即可
messageSender.setRoutingKey("message.*");
// 发送消息
messageSender.sendDataToQueue("queue insert Queue");

logger.info("to send message:{}","insert Queue");

return "{\"key\" : \"value\"}";
}

@RequestMapping(value = "/doValid1")
@ResponseBody
public String doValid1() {

// 设置RoutingKey,匹配message.*即可
messageSender1.setRoutingKey("message.*");
// 发送消息
messageSender1.sendDataToQueue("queue1 insert Queue");

logger.info("to send message:{}","insert Queue");

return "{\"key\" : \"value\"}";
}

@RequestMapping(value = "/doValid2")
@ResponseBody
public String doValid2() {

// 设置RoutingKey,匹配message.*即可
messageSender2.setRoutingKey("message.*");
// 发送消息
messageSender2.sendDataToQueue("queue2 insert Queue");

logger.info("to send message:{}","insert Queue");

return "{\"key\" : \"value\"}";
}
}




 
 

原文地址:https://www.cnblogs.com/cw828/p/11939948.html

时间: 2024-11-11 00:53:35

linux安装rabbitmq ssm集成rabbitmq的相关文章

springboot集成RabbitMQ,Eclipse开发集成RabbitMq,IDEA集成RabbitMQ报错 socket close

java.net.SocketException: socket closed    at java.net.SocketInputStream.socketRead0(Native Method)    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)    at java.net.SocketInputStream.read(SocketInputStream.java:170)    at java.n

6.RabbitMQ Linux安装

RabbitMQ在Linux上安装,需要很多依赖库,如何不能解决依赖库德版本问题,可能会比较麻烦,最好结合Yum进行安装,我这里使用的Linux环境是64位CentOS6.2 ,使用Yum源是阿里云的 CentOS 6 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 还单独下载了RabbitMQ安装RPM包 按照如下步骤进行安装: 1.删除或备份原来的Yum源 #cd  

4.RabbitMQ Linux安装

这里使用的Linux是CentOS6.2 将/etc/yum.repo.d/目录下的所有repo文件删除 先下载epel源 # wget -O  /etc/yum.repos.d/epel-erlang.repo http://repos.fedorapeople.org/repos/peter/erlang/epel-erlang.repo 修改epel-erlang.repo文件,如下图 添加CentOS 的下载源为阿里云 CentOS 6 wget -O /etc/yum.repos.d/

服务器搭建--Linux安装rabbitmq

安装rabbitmq需要先安装erlang:安装erlang参考https://blog.csdn.net/ztx114/article/details/79912570 1.下载rabbitmq-server-generic-unix-3.6.15.tar.xz 我是安装在/usr/local/soft/目录下,首先切换到/usr/local/soft/目录没有soft文件夹的需要先创建文件夹: cd /usr/local/soft/[[email protected] soft]# tar

RabbitMQ Linux 安装教程

一.安装 Erlang环境 cd /usr/local/src/ mkdir rabbitmq cd rabbitmq wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm rpm -Uvh erlang-solutions-1.0-1.noarch.rpm rpm --import http://packages.erlang-solutions.com/rpm/erlang_solutions.

SpringBoot | 第十二章:RabbitMQ的集成和使用

前言 上节讲了缓存数据库redis的使用,在实际工作中,一般上在系统或者应用间通信或者进行异步通知(登录后发送短信或者邮件等)时,都会使用消息队列进行解决此业务场景的解耦问题.这章节讲解下消息队列RabbitMQ的集成和简单使用示例. RabbitMQ介绍 SpringBoot集成RabbitMQ 总结 最后 老生常谈 RabbitMQ介绍 RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种客户端,如:Python.Ruby..NET.Java.JMS.C.PHP

SpringBoot集成rabbitmq(一)

前言 Rabbitmq是一个开源的消息代理软件,是AMQP协议的实现.核心作用就是创建消息队列,异步发送和接收消息.通常用来在高并发中处理削峰填谷.延迟处理.解耦系统之间的强耦合.处理秒杀订单.  入门rabbitmq之前主要是想了解下秒杀排队订单入库后,异步通知客户端秒杀结果. 基础知识 1.基本概念(角色) 了解rabbitmq之前先要了解3个基本概念:生产者.消费者.代理(队列). rabbitmq在生产者和代理中间做了一层抽象.这样消息生产者和队列就没有直接联系,在中间加入了一层交换器(

Dapr Pub/Sub 集成 RabbitMQ 、Golang、Java、DotNet Core

前置条件: <Dapr运用> <Dapr 运用之 Java gRPC 调用篇> <Dapr 运用之集成 Asp.Net Core Grpc 调用篇> 搭建 RabbitMQ Docker 搭建 RabbitMQ 服务 docker run -d --hostname my-rabbit --name some-rabbit -p 5672:5672 -p 15672:15672 rabbitmq:3-management 创建 rabbiqmq.yaml apiVers

安装Docker,运行RabbitMQ镜像

Docker用起来有多方便,笔者就不瞎说了.反正谁永谁知道.为了配合前面的SpringCloud Bus学习,笔者就顺带安装了Docker.写这篇文章的目的,是为了给 SpringCloud微服务入门(九),统一配置中心Config作补充. 跟着镜头切换,随笔者开启Docker的大门.打开https://hub.docker.com/search?q=&type=edition&offering=community&sort=updated_at&order=desc找到符