PageRenderTime 84ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/java/com/udfex/demo/activemq/ProducerClient.java

https://gitlab.com/tanxinzheng/activemq-api
Java | 48 lines | 36 code | 7 blank | 5 comment | 0 complexity | fb85a63a952650ec07cf4b9aa35ecf4a MD5 | raw file
  1. package com.udfex.demo.activemq;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.udfex.ucs.amq.api.*;
  4. import org.apache.activemq.ActiveMQConnectionFactory;
  5. import java.util.Date;
  6. import java.util.Properties;
  7. public class ProducerClient {
  8. public static void main(String[] args) {
  9. Properties properties = new Properties();
  10. properties.put(ProducerConst.TOPIC, "GUEST.PID_UDFEX_PRODUCER_TEST_00001");
  11. //properties.put(PropertyKeyConst.AccessKey, "4ZY3Hr1k3VSOi6PW");
  12. //properties.put(PropertyKeyConst.SecretKey, "OM44UesEeGvmxfpu3LKtb4PvzVTw55");
  13. SimpleTransportListener simpleTransportListener = new SimpleTransportListener();
  14. ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
  15. activeMQConnectionFactory.setTransportListener(simpleTransportListener);
  16. activeMQConnectionFactory.setBrokerURL("failover:(tcp://192.168.8.211:61616)");
  17. IAMQFactory iamqFactory = new IAMQFactory(activeMQConnectionFactory);
  18. Producer producer = iamqFactory.createProducer(properties);
  19. MockData data = new MockData();
  20. data.setId("000001");
  21. data.setAge(12);
  22. data.setBirthDay(new Date());
  23. data.setName("测试队列1");
  24. DataMessage dataMessage = new DataMessage();
  25. dataMessage.setTopic("GUEST.PID_UDFEX_PRODUCER_TEST_00002");
  26. dataMessage.setMessageBody(JSONObject.toJSONString(data));
  27. producer.send(dataMessage);
  28. Properties properties2 = new Properties();
  29. properties2.put(ProducerConst.TOPIC, "GUEST.PID_UDFEX_PRODUCER_TEST_00002");
  30. //properties.put(PropertyKeyConst.AccessKey, "4ZY3Hr1k3VSOi6PW");
  31. //properties.put(PropertyKeyConst.SecretKey, "OM44UesEeGvmxfpu3LKtb4PvzVTw55");
  32. activeMQConnectionFactory.setBrokerURL("failover:(tcp://192.168.8.211:61616)");
  33. Producer producer2 = iamqFactory.createProducer(properties2);
  34. MockData2 data2 = new MockData2();
  35. data2.setId("000002");
  36. data2.setAge(22);
  37. data2.setBirthDay(new Date());
  38. data2.setName("测试队列2");
  39. //producer2.send(JSONObject.toJSONString(data2));
  40. }
  41. }