行业网站方案,软件开发平台都有哪些,企业展馆策划公司,高密做网站哪家好代理五种消息模型简单说明
RabbitMQ提供了6种消息模型#xff0c;但是第6种其实是RPC#xff0c;并不是MQ#xff0c;因此不予学习。那么也就剩下5种。但是其实3、4、5这三种都属于订阅模型#xff0c;只不过进行路由的方式不同。
我们通过一个demo工程来了解下RabbitMQ的…五种消息模型简单说明
RabbitMQ提供了6种消息模型但是第6种其实是RPC并不是MQ因此不予学习。那么也就剩下5种。但是其实3、4、5这三种都属于订阅模型只不过进行路由的方式不同。
我们通过一个demo工程来了解下RabbitMQ的工作方式导入工程
依赖
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.atguigu.rabbitmq/groupIdartifactIdrabbitmq-demo/artifactIdversion1.0-SNAPSHOT/versionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.1.9.RELEASE/version/parentpropertiesjava.version1.8/java.version/propertiesdependenciesdependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactIdversion3.3.2/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-amqp/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactId/dependency/dependencies
/project 我们抽取一个建立RabbitMQ连接的工具类方便其他程序获取连接
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import java.io.IOException;
public class ConnectionUtil {/*** 建立与RabbitMQ的连接*/public static Connection getConnection() throws Exception {//定义连接工厂ConnectionFactory factory new ConnectionFactory();//设置服务地址factory.setHost(192.168.137.137);//端口factory.setPort(5672);//设置账号信息用户名、密码、vhostfactory.setVirtualHost(/shopping);factory.setUsername(zhangsan);factory.setPassword(123456);// 通过工程获取连接Connection connection factory.newConnection();return connection;}public static void main(String[] args) throws Exception {Connection con ConnectionUtil.getConnection();System.out.println(con);con.close();}
}