zoukankan      html  css  js  c++  java
  • Java连接RabbitMQ之创建连接

    依赖包:

     1 <dependencies>
     2     <dependency>
     3       <groupId>junit</groupId>
     4       <artifactId>junit</artifactId>
     5       <version>4.12</version>
     6       <scope>test</scope>
     7     </dependency>
     8 
     9     <!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
    10     <dependency>
    11       <groupId>com.rabbitmq</groupId>
    12       <artifactId>amqp-client</artifactId>
    13       <version>5.1.2</version>
    14     </dependency>
    15     <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
    16     <dependency>
    17       <groupId>org.slf4j</groupId>
    18       <artifactId>slf4j-nop</artifactId>
    19       <version>1.7.25</version>
    20     </dependency>
    21 
    22   </dependencies>

    源码:

     1 package org.study.utils;
     2 
     3 import com.rabbitmq.client.Connection;
     4 import com.rabbitmq.client.ConnectionFactory;
     5 
     6 import java.io.IOException;
     7 import java.util.concurrent.TimeoutException;
     8 
     9 /**
    10  * 获取rabbitmq连接
    11  */
    12 public class ConnectionUtils {
    13     public static Connection getConnection() throws IOException, TimeoutException {
    14         ConnectionFactory factory = new ConnectionFactory();
    15         factory.setHost("10.15.1.26");
    16         factory.setPort(5672);
    17         factory.setVirtualHost("/test_host");
    18         factory.setUsername("admin");
    19         factory.setPassword("admin");
    20         Connection connection = factory.newConnection();
    21         return connection;
    22     }
    23 }
  • 相关阅读:
    水晶报表的部署
    成熟是一种明亮而不刺眼的光辉...
    获取页面地址的各种返回值
    索引的基本原理(转)
    cron
    VS2010 测试 普通单元测试
    SQL 学习笔记
    负载均衡
    Expression 常用方法
    轻松实现QQ用户接入
  • 原文地址:https://www.cnblogs.com/gongxr/p/9639489.html
Copyright © 2011-2022 走看看