Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EmbeddedPublisher {
- public static void main(String... args) {
- try {
- /**
- * this map with configuration values is not necessary (it configures the default values).
- * If you modify it to run the example in two different hosts, remember to also modify the
- * server's Acceptor at {@link EmbeddedServer}
- */
- Map<String, Object> map = new HashMap<>();
- map.put("host", "localhost");
- map.put("port", 5445);
- // -------------------------------------------------------
- ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), map));
- ClientSessionFactory sf = serverLocator.createSessionFactory();
- // Step 5. Create the session, and producer
- try (ClientSession session = sf.createSession()) {
- try (ClientProducer producer = session.createProducer(Properties.queueName)) {
- // Step 6. Create and send a message
- ClientMessage message = session.createMessage(false);
- //message.putStringProperty(Properties.propName, "Hello sent at " + new Date());
- ObjectMapper mapper = new ObjectMapper();
- Map<String, Object> pojoMap = mapper.convertValue(new Pojo(13, "name", "phone"), new TypeReference<Map<String, Object>>() {});
- pojoMap.forEach(message::putObjectProperty);
- System.out.println("Sending the message.. " + pojoMap.toString());
- producer.send(message);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement