Producer.java 695 B

1234567891011121314151617181920212223
  1. package com.sf.workqueue;
  2. import com.rabbitmq.client.Channel;
  3. import com.sf.util.MqUtils;
  4. import java.util.Scanner;
  5. public class Producer {
  6. private final static String QUEUE_NAME = "hello2";
  7. public static void main(String[] args) throws Exception {
  8. Channel channel = MqUtils.getChannel();
  9. channel.queueDeclare(QUEUE_NAME, false, false, false, null);
  10. Scanner scanner = new Scanner(System.in);
  11. System.out.println("请输入消息:");
  12. while (scanner.hasNext()) {
  13. String message = scanner.next();
  14. System.out.println(message);
  15. channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
  16. }
  17. }
  18. }