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 }
  • 相关阅读:
    移动端常用单位——rem
    媒体查询media query
    canvas——绘制解锁图案
    canvas——离屏
    canvas——动画实例
    canvas绘制圆弧
    canvas二次贝塞尔&三次贝塞尔操作实例
    form表单中id与name的区别
    数据存储 mysql
    数据存储 csv
  • 原文地址:https://www.cnblogs.com/gongxr/p/9639489.html
Copyright © 2011-2022 走看看