Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EmbeddedConsumer {
- 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
- try (ClientSession session = sf.createSession()) {
- session.start();
- try (ClientConsumer consumer = session.createConsumer(Properties.queueName)) {
- consumer.setMessageHandler(message -> {
- ObjectMapper mapper = new ObjectMapper();
- mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- Pojo pojo = mapper.convertValue(mapJson, Pojo.class);
- });
- TimeUnit.MINUTES.sleep(1);
- session.close();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement