Advertisement
Guest User

EmbeddedConsumer

a guest
Mar 31st, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. public class EmbeddedConsumer {
  2.  
  3.     public static void main(String... args) {
  4.         try {
  5.  
  6.             /**
  7.              * this map with configuration values is not necessary (it configures the default values).
  8.              * If you modify it to run the example in two different hosts, remember to also modify the
  9.              * server's Acceptor at {@link EmbeddedServer}
  10.              */
  11.             Map<String, Object> map = new HashMap<>();
  12.             map.put("host", "localhost");
  13.             map.put("port", 5445);
  14.             // -------------------------------------------------------
  15.  
  16.             ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), map));
  17.             ClientSessionFactory sf = serverLocator.createSessionFactory();
  18.  
  19.             // Step 5. Create the session
  20.             try (ClientSession session = sf.createSession()) {
  21.                 session.start();
  22.  
  23.                 try (ClientConsumer consumer = session.createConsumer(Properties.queueName)) {
  24.  
  25.                     consumer.setMessageHandler(message -> {
  26.                         ObjectMapper mapper = new ObjectMapper();
  27.                         mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
  28.                      
  29.                         Pojo pojo = mapper.convertValue(mapJson, Pojo.class);
  30.                     });
  31.  
  32.                     TimeUnit.MINUTES.sleep(1);
  33.                     session.close();
  34.                 }
  35.             }
  36.         } catch (Exception e) {
  37.             e.printStackTrace();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement