当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionFactory类代码示例

本文整理汇总了Java中com.rabbitmq.client.ConnectionFactory的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory类的具体用法?Java ConnectionFactory怎么用?Java ConnectionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionFactory类属于com.rabbitmq.client包,在下文中一共展示了ConnectionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setUsername("guest");
	factory.setPassword("guest");
	factory.setVirtualHost("/");
	factory.setHost("localhost");
	factory.setPort(5672);
	Connection newConnection = factory.newConnection();

	Channel channel = newConnection.createChannel();

	Scanner scanner = new Scanner(System.in);
	String message = "";
	while(!message.equals("exit")){
		System.out.println("Enter your message");
		message = scanner.next();
		channel.queueDeclare("flink-test", true, false, false, null);
		channel.basicPublish("", "flink-test", new BasicProperties.Builder()
				.correlationId(java.util.UUID.randomUUID().toString()).build(), message.getBytes());
	}
	
	scanner.close();
	channel.close();
	newConnection.close();
}
 
开发者ID:PacktPublishing,项目名称:Practical-Real-time-Processing-and-Analytics,代码行数:26,代码来源:RMQPublisher.java

示例2: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {
  ConnectionFactory factory = new ConnectionFactory();
  factory.setHost("localhost");
  Connection connection = factory.newConnection();
  Channel channel = connection.createChannel();

  channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT);

  String message = getMessage(argv);

  channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes("UTF-8"));
  System.out.println(" [x] Sent '" + message + "'");

  channel.close();
  connection.close();
}
 
开发者ID:bmariesan,项目名称:iStudent,代码行数:17,代码来源:EmitLog.java

示例3: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
public static void main(String[] args) throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException, IOException, InterruptedException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUri("amqp://guest:[email protected]");
    factory.setConnectionTimeout(300000);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare("my-queue", true, false, false, null);

    int count = 0;

    while (count < 5000) {
        String message = "Message number " + count;

        channel.basicPublish("", "my-queue", null, message.getBytes());
        count++;
        System.out.println("Published message: " + message);

        Thread.sleep(5000);
    }
}
 
开发者ID:nyholmniklas,项目名称:rabbitmq-tutorial,代码行数:22,代码来源:Publisher.java

示例4: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection conn = factory.newConnection();
    Channel channel = conn.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT);

    String msg = getMessage(argv);

    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy @ HH:mm:ss");
    String sDate = sdf.format(date);

    String finalMsg = sDate + ": " + msg;

    channel.basicPublish(EXCHANGE_NAME, "", null, finalMsg.getBytes("UTF-8"));
    System.out.println("Emmited message: " + finalMsg);

    channel.close();
    conn.close();
}
 
开发者ID:VictorFerraresi,项目名称:simple-rabbitmq-logger,代码行数:23,代码来源:Emitter.java

示例5: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
/**
 * @param args
 * @throws IOException
 * @throws TimeoutException
 * @date 2017年7月11日 下午5:53:02
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	
	Connection connection = factory.newConnection();
	Channel channel = connection.createChannel();
	channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
	// 分发信息
	for (int i = 0; i < 20; i++) {
		String message = "Hello RabbitMQ" + i;
		channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
		System.out.println("NewTask send '" + message + "'");
	}
	channel.close();
	connection.close();
}
 
开发者ID:pudoj,项目名称:june.mq,代码行数:28,代码来源:NewTask.java

示例6: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
/**
 * @param args
 * @throws TimeoutException
 * @throws IOException
 * @date 2017年7月13日 下午2:49:49
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {

	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection connection = factory.newConnection();
	Channel channel = connection.createChannel();
	// 声明交换机
	channel.exchangeDeclare(EXCHANGE_NAME_ROUTING, "direct");// 注意是direct
	// 发送信息
	for (String routingKey : routingKeys) {
		String message = "RoutingSendDirect Send the message level:" + routingKey;
		channel.basicPublish(EXCHANGE_NAME_ROUTING, routingKey, null, message.getBytes());
		System.out.println("RoutingSendDirect Send" + routingKey + "':'" + message);
	}
	channel.close();
	connection.close();
}
 
开发者ID:pudoj,项目名称:june.mq,代码行数:29,代码来源:RoutingSendDirect.java

示例7: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {
		ConnectionFactory factory = new ConnectionFactory();
//		factory.setHost("");
		factory.setUri("amqp://alpha.netkiller.cn");
		factory.setUsername("admin");
//		factory.setPassword("admin123");
		Connection connection = factory.newConnection();
		Channel channel = connection.createChannel();

		channel.queueDeclare(QUEUE_NAME, false, false, false, null);
		String message = "Hello World!";
		channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
		System.out.println(" [x] Sent '" + message + "'");

		channel.close();
		connection.close();
	}
 
开发者ID:netkiller,项目名称:ipo,代码行数:18,代码来源:RabbitMQTest.java

示例8: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

    String severity = getSeverity(argv);
    String message = getMessage(argv);

    channel.basicPublish(EXCHANGE_NAME, severity, null, message.getBytes("UTF-8"));
    System.out.println(" [x] Sent '" + severity + "':'" + message + "'");

    channel.close();
    connection.close();
  }
 
开发者ID:bmariesan,项目名称:iStudent,代码行数:19,代码来源:EmitLogDirect.java

示例9: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {
  ConnectionFactory factory = new ConnectionFactory();
  factory.setHost("localhost");
  Connection connection = factory.newConnection();
  Channel channel = connection.createChannel();

  channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);

  String message = getMessage(argv);

  channel.basicPublish("", TASK_QUEUE_NAME,
      MessageProperties.PERSISTENT_TEXT_PLAIN,
      message.getBytes("UTF-8"));
  System.out.println(" [x] Sent '" + message + "'");

  channel.close();
  connection.close();
}
 
开发者ID:bmariesan,项目名称:iStudent,代码行数:19,代码来源:NewTask.java

示例10: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
/**
 * @param args
 * @throws TimeoutException
 * @throws IOException
 * @date 2017年7月13日 下午2:37:37
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection connection = factory.newConnection();
	Channel channel = connection.createChannel();

	channel.exchangeDeclare(EXCHANGE_NAME, "fanout");// fanout表示分发,所有的消费者得到同样的队列信息
	// 分发信息
	for (int i = 0; i < 5; i++) {
		String message = "Hello World" + i;
		channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
		System.out.println("EmitLog Sent '" + message + "'");
	}
	channel.close();
	connection.close();

}
 
开发者ID:pudoj,项目名称:june.mq,代码行数:29,代码来源:EmitLog.java

示例11: updateTaskStatus

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
private void updateTaskStatus(TaskStatus status) {
    logger.info("[Study = " + taskStudy + "] [Unit = "+ unitId + "] Sending task update to server. Task id = [" + task.getId() + "] status = ["+status.toString()+"]");
    final String QUEUE_NAME =  SystemConstants.UBONGO_SERVER_TASKS_STATUS_QUEUE;
    try {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(serverAddress);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        task.setStatus(status);
        RabbitData message = new RabbitData(task, MachineConstants.UPDATE_TASK_REQUEST);
        channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
        if (logger.isDebugEnabled()) {
            logger.debug(" [!] Sent '" + message.getMessage() + "'");
        }
        channel.close();
        connection.close();
    } catch (Exception e){
        logger.error("[Study = " + taskStudy + "] [Unit = "+ unitId + "] Failed sending task status to server. Task id = [" + task.getId() + "] Status = [" +
                status.toString() + "] error: " + e.getMessage(), e);
    }
}
 
开发者ID:razreg,项目名称:ubongo,代码行数:23,代码来源:RequestHandler.java

示例12: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    String queueName = "TestQueue";
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("127.0.0.1");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(queueName, false, false, false, null);
    System.out.println(" [*] Waiting for messages...");

    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(queueName, true, consumer);

    while (true) {
        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
        String message = new String(delivery.getBody());
        System.out.println(" [x] Received '" + message + "'");
    }
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:20,代码来源:Consumer.java

示例13: consumeWithoutCertificate

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
/**
 * Helper method to retrieve queue message from rabbitMQ
 *
 * @return result
 * @throws Exception
 */
private static String consumeWithoutCertificate() throws Exception {
    String result = "";
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    factory.setPort(5671);
    factory.useSslProtocol();

    Connection conn = factory.newConnection();
    Channel channel = conn.createChannel();

    GetResponse chResponse = channel.basicGet("WithoutClientCertQueue", true);
    if(chResponse != null) {
        byte[] body = chResponse.getBody();
        result = new String(body);
    }
    channel.close();
    conn.close();
    return result;
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:26,代码来源:ESBJAVA4569RabbiMQSSLStoreWithoutClientCertValidationTest.java

示例14: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        //建立连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置连接地址
        factory.setHost("seaof-153-125-234-173.jp-tokyo-10.arukascloud.io");
        factory.setPort(31084);
        //获取连接
        Connection connection = factory.newConnection();
        //获取渠道
        Channel channel = connection.createChannel();

        //声明交换机类型
        channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

        //产生随机数字
        String message = RandomStringUtils.randomNumeric(8);

        channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());

        channel.close();
        connection.close();

    }
 
开发者ID:liubo6,项目名称:demo_springboot_rabbitmq,代码行数:25,代码来源:EmitLog.java

示例15: main

import com.rabbitmq.client.ConnectionFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException, TimeoutException {

        //建立连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置连接地址
        factory.setHost("seaof-153-125-234-173.jp-tokyo-10.arukascloud.io");
        factory.setPort(31084);
        //获取连接
        Connection connection = factory.newConnection();
        //获取渠道
        Channel channel = connection.createChannel();
        //声明队列,如果不存在就新建
        //参数1队列名称;参数2是否持久化;参数3排他性队列,连接断开自动删除;参数4是否自动删除;参数5.参数
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        //发送的消息
        String message = Thread.currentThread().getName() + "Hello ";

        //参数1 交换机;参数2 路由键;参数3 基础属性;参数4 消息体
        channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
        System.out.println(Thread.currentThread().getName() + "[send]" + message);
        channel.close();
        connection.close();

    }
 
开发者ID:liubo6,项目名称:demo_springboot_rabbitmq,代码行数:25,代码来源:Send.java


注:本文中的com.rabbitmq.client.ConnectionFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。