1234567891011121314151617181920212223 |
- package com.sf.workqueue;
- import com.rabbitmq.client.Channel;
- import com.sf.util.MqUtils;
- import java.util.Scanner;
- public class Producer {
- private final static String QUEUE_NAME = "hello2";
- public static void main(String[] args) throws Exception {
- Channel channel = MqUtils.getChannel();
- channel.queueDeclare(QUEUE_NAME, false, false, false, null);
- Scanner scanner = new Scanner(System.in);
- System.out.println("请输入消息:");
- while (scanner.hasNext()) {
- String message = scanner.next();
- System.out.println(message);
- channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
- }
- }
- }
|