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


Java Channel.queueDeclare方法代码示例

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


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

示例1: main

import com.rabbitmq.client.Channel; //导入方法依赖的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.Channel; //导入方法依赖的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

示例3: main

import com.rabbitmq.client.Channel; //导入方法依赖的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

示例4: main

import com.rabbitmq.client.Channel; //导入方法依赖的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

示例5: main

import com.rabbitmq.client.Channel; //导入方法依赖的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

示例6: updateTaskStatus

import com.rabbitmq.client.Channel; //导入方法依赖的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

示例7: main

import com.rabbitmq.client.Channel; //导入方法依赖的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

示例8: run

import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
@Override
public void run(AppConfiguration configuration, Environment environment) throws Exception {
    SessionFactory sessionFactory = hibernate.getSessionFactory();
    MemoDAO memoDAO = new MemoDAO(sessionFactory);

    QueueConfig queueConfig = configuration.getQueueConfig();
    ConnectionFactory connectionFactory = QueueHelper.getQueue(queueConfig);

    Channel channel = connectionFactory.newConnection().createChannel();

    channel.exchangeDeclare(queueConfig.getExchangeName(), "direct", true);
    channel.queueDeclare(queueConfig.getQueueName(), true, false, false, null);
    channel.queueBind(queueConfig.getQueueName(), queueConfig.getExchangeName(), queueConfig.getRoutingKey());

    channel.basicConsume(queueConfig.getQueueName(), false, "myConsumerTag", new MemoWorker(memoDAO, channel, sessionFactory));

}
 
开发者ID:aytechnologies,项目名称:heroku-gradle-dropwizard,代码行数:18,代码来源:WorkerApplication.java

示例9: main

import com.rabbitmq.client.Channel; //导入方法依赖的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

示例10: GabrielGatewayClient

import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
public GabrielGatewayClient(int shardId, Channel channel) throws IOException {
    super(shardId, channel, true);
    channel.queueDeclare("shard-" + shardId + "-getping", false, false, false, null);
    channel.queueDeclare("shard-" + shardId + "-getping-response", false, false, false, null);
    channel.basicConsume("shard-" + shardId + "-getping-response", true, new DefaultConsumer(channel) {
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            long now = System.currentTimeMillis();
            ping = now - Longs.fromByteArray(body);
        }
    });
    calculatePing();
    PING_CALCULATOR.scheduleAtFixedRate(this::calculatePing, 30, 30, TimeUnit.SECONDS);
}
 
开发者ID:natanbc,项目名称:GabrielBot,代码行数:15,代码来源:GabrielGatewayClient.java

示例11: init

import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
public static synchronized void init(Channel channel) throws IOException, TimeoutException {
    if(current != null) {
        throw new IllegalStateException("Already started");
    }
    current = new GatewayInfo("unknown", "unknown", -1, -1, -1, -1, -1, -1, -1);
    channel.queueDeclare("gateway-info", false, false, false, null);
    channel.basicConsume("gateway-info", true, new DefaultConsumer(channel) {
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            JSONObject object = new JSONObject(new String(body, StandardCharsets.UTF_8));
            JSONObject ram = object.getJSONObject("ram");
            try {
                current = new GatewayInfo(
                        object.getString("version"),
                        object.getString("jda-version"),
                        object.getDouble("cpu-usage"),
                        object.getInt("thread-count"),
                        object.getLong("uptime"),
                        ram.getLong("used"),
                        ram.getLong("free"),
                        ram.getLong("total"),
                        ram.getLong("max")
                );
            } catch(JSONException e) {
                GabrielBot.LOGGER.error("Error creating GatewayInfo: " + e.getMessage());
            }
        }
    });
}
 
开发者ID:natanbc,项目名称:GabrielBot,代码行数:30,代码来源:GatewayInfo.java

示例12: main

import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
/**
 * @param args
 * @throws TimeoutException
 * @throws IOException
 * @date 2017年7月11日 下午5:21:46
 * @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 = null;
	Channel channel = null;
	try {
		// 创建一个新的连接
		connection = factory.newConnection();
		// 创建一个通道
		channel = connection.createChannel();
		// 声明一个队列
		// queueDeclare第一个参数表示队列名称
		//第二个参数为是否持久化(true表示是,队列将在服务器重启时生存)
		//第三个参数为是否是独占队列(创建者可以使用的私有队列,断开后自动删除)
		//第四个参数为当所有消费者客户端连接断开时是否自动删除队列
		//第五个参数为队列的其他参数
		channel.queueDeclare(QUEUE_NAME, false, false, false, null);
		String message = "{\"temperature\":100}";
		// 发送消息到队列中
		//basicPublish第一个参数为交换机名称
		//第二个参数为队列映射的路由key
		//第三个参数为消息的其他属性
		//第四个参数为发送信息的主体
		channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
		System.out.println("Producer Send +'" + message + "'");

	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		// 关闭通道和连接
		channel.close();
		connection.close();
	}
}
 
开发者ID:pudoj,项目名称:june.mq,代码行数:46,代码来源:Producer.java

示例13: main

import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
/**
 * @param args
 * @throws TimeoutException
 * @throws IOException
 * @date 2017年7月11日 下午5:32:45
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	// 创建连接工厂
	ConnectionFactory factory = new ConnectionFactory();
	// 设置RabbitMQ地址
	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(QUEUE_NAME, false, false, false, null);
	System.out.println("Customer Waiting Received messages");
	// DefaultConsumer类实现了Consumer接口,通过传入一个频道,
	// 告诉服务器我们需要那个频道的消息,如果频道中有消息,就会执行回调函数handleDelivery
	Consumer consumer = new DefaultConsumer(channel) {
		//envelope主要存放生产者相关信息(比如交换机、路由key等)
		//body是消息实体
		@Override
		public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
				byte[] body) throws IOException {
			String message = new String(body, "UTF-8");
			System.out.println("Customer Received '" + message + "'");
		}
	};
	// 自动回复队列应答 -- RabbitMQ中的消息确认机制
	channel.basicConsume(QUEUE_NAME, true, consumer);
}
 
开发者ID:pudoj,项目名称:june.mq,代码行数:39,代码来源:Customer.java

示例14: initChannel

import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
private void initChannel(Channel channel) throws IOException {
    channel.basicQos(1);
    // this.channel.exchangeDeclare(this.exchange, TOPIC);
    Map<String, Object> args = new HashMap<>();
    args.put("x-expires", 180000); // Three minutes
    channel.queueDeclare(QUEUE_NAME, true, true, true, args);
    channel.queueBind(QUEUE_NAME, NOVA_EXCHANGE, ROUTING_KEY);
    channel.queueBind(QUEUE_NAME, NEUTRON_EXCHANGE, ROUTING_KEY);
    channel.queueBind(QUEUE_NAME, KEYSTONE_EXCHANGE, ROUTING_KEY);
    channel.queueBind(this.queue, this.exchange, this.routingKey);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:12,代码来源:RabbitMQClient.java

示例15: send

import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
@POST
@Path("rabbitmqRecv")
public void send() throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setUsername("guest");
    factory.setPassword("guest");
    factory.setHost("127.0.0.1");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    DefaultConsumer consumer = new DefaultConsumer(channel) {

        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                byte[] body) throws IOException {

            System.out.println(properties.getHeaders());
            String message = new String(body, "UTF-8");
            System.out.println(" [x] Received '" + message + "'");
        }
    };
    channel.basicConsume(QUEUE_NAME, true, consumer);
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:28,代码来源:RabbitMQRecv.java


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