Java Code Examples for org.springframework.jms.annotation.JmsListener

The following examples show how to use org.springframework.jms.annotation.JmsListener. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hdw-dubbo   Source File: ActiveMQReceiveMsgService.java    License: Apache License 2.0 6 votes vote down vote up
@JmsListener(destination = "ActiveMQ.Advisory.Connection", containerFactory = "topicJmsListenerContainerFactory", concurrency = "5-10")
public void advisoryConnection(Message msg) {
    try {
        if (msg instanceof ActiveMQMessage) {
            ActiveMQMessage aMsg = (ActiveMQMessage) msg;
            if (aMsg.getDataStructure() instanceof ConnectionInfo) {
                ConnectionInfo connectionInfo = (ConnectionInfo) aMsg.getDataStructure();
                log.info("连接信息:" + JacksonUtil.toJson(connectionInfo));
            } else if (aMsg.getDataStructure() instanceof RemoveInfo) {
                RemoveInfo removeInfo = (RemoveInfo) aMsg.getDataStructure();
                log.info("移除信息:" + JacksonUtil.toJson(removeInfo));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 2
Source Project: paas   Source File: MQConsumer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 接收邮箱注册消息
 * @author jitwxs
 * @since 2018/7/9 16:05
 */
@JmsListener(destination = "MQ_QUEUE_REGISTER")
public void receiveRegister(String text) {
    if(StringUtils.isNotBlank(text)){
        Task task = JsonUtils.jsonToObject(text, Task.class);

        Map<String, String> map = task.getData();
        String email = map.get("email");
        log.info("验证未激活邮箱,目标邮箱:{}", email);

        SysLogin login = loginService.getByEmail(email);
        if(login != null && login.getHasFreeze()) {
            loginService.deleteById(login);
        }
    }
}
 
Example 3
Source Project: paas   Source File: MQConsumer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 接收容器信息
 * @author jitwxs
 * @since 2018/7/9 17:08
 */
@JmsListener(destination = "MQ_QUEUE_CONTAINER")
public void receiveContainer(String text) {
    if (StringUtils.isNotBlank(text)) {
        Task task = JsonUtils.jsonToObject(text, Task.class);

        Map<String, String> map = task.getData();
        String userId = map.get("uid");

        String field = ID_PREFIX + userId;
        try {
            String sessionId = jedisClient.hget(key, field);
            if (StringUtils.isNotBlank(sessionId)) {
                webSocketServer.sendMessage(map.get("data"), sessionId);
            } else {
                throw new Exception("session未找到");
            }
        } catch (Exception e) {
            log.error("接收容器消息错误,错误位置:{},错误信息:{}", "MQConsumer.receiveContainer()", e.getMessage());
        }
    }
}
 
Example 4
Source Project: paas   Source File: MQConsumer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 接收系统镜像信息
 * @author jitwxs
 * @since 2018/7/9 17:08
 */
@JmsListener(destination = "MQ_QUEUE_SYS_IMAGE")
public void receiveSysImage(String text) {
    if (StringUtils.isNotBlank(text)) {
        Task task = JsonUtils.jsonToObject(text, Task.class);

        Map<String, String> map = task.getData();
        String userId = map.get("uid");

        String field = ID_PREFIX + userId;
        try {
            String sessionId = jedisClient.hget(key, field);
            if (StringUtils.isNotBlank(sessionId)) {
                webSocketServer.sendMessage(map.get("data"), sessionId);
            } else {
                throw new Exception("session未找到");
            }
        } catch (Exception e) {
            log.error("接收系统镜像消息错误,错误位置:{},错误信息:{}", "MQConsumer.receiveSysImage()", e.getMessage());
        }
    }
}
 
Example 5
Source Project: paas   Source File: MQConsumer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 接收HUB镜像信息
 * @author jitwxs
 * @since 2018/7/9 17:08
 */
@JmsListener(destination = "MQ_QUEUE_HUB_IMAGE")
public void receiveHubImage(String text) {
    if (StringUtils.isNotBlank(text)) {
        Task task = JsonUtils.jsonToObject(text, Task.class);

        Map<String, String> map = task.getData();
        String userId = map.get("uid");

        String field = ID_PREFIX + userId;
        try {
            String sessionId = jedisClient.hget(key, field);
            if (StringUtils.isNotBlank(sessionId)) {
                webSocketServer.sendMessage(map.get("data"), sessionId);
            } else {
                throw new Exception("session未找到");
            }
        } catch (Exception e) {
            log.error("接收HUB镜像消息错误,错误位置:{},错误信息:{}", "MQConsumer.receiveHubImage()", e.getMessage());
        }
    }
}
 
Example 6
Source Project: paas   Source File: MQConsumer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 接收服务信息
 * @author hf
 * @since 2018/7/13 17:08
 */
@JmsListener(destination = "MQ_QUEUE_SERVICE")
public void receiveService(String text) {
    if (StringUtils.isNotBlank(text)) {
        Task task = JsonUtils.jsonToObject(text, Task.class);

        Map<String, String> map = task.getData();
        String userId = map.get("uid");
        ResultVO resultVO = JsonUtils.jsonToObject(map.get("data"), ResultVO.class);

        String field = ID_PREFIX + userId;
        try {
            String sessionId = jedisClient.hget(key, field);
            if (StringUtils.isNotBlank(sessionId)) {
                webSocketServer.sendMessage(JsonUtils.objectToJson(resultVO), sessionId);
            } else {
                throw new Exception("session未找到");
            }
        } catch (Exception e) {
            log.error("接收服务消息错误,错误位置:{},错误信息:{}", "MQConsumer.receiveService()", e.getMessage());
        }
    }
}
 
Example 7
Source Project: paas   Source File: MQConsumer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 接收通知信息
 * @author hf
 * @since 2018/7/13 17:08
 */
@JmsListener(destination = "MQ_QUEUE_NOTICE")
public void receiveNotice(String text) {
    if (StringUtils.isNotBlank(text)) {
        Task task = JsonUtils.jsonToObject(text, Task.class);

        Map<String, String> map = task.getData();
        String userId = map.get("uid");
        ResultVO resultVO = JsonUtils.jsonToObject(map.get("data"), ResultVO.class);

        String field = ID_PREFIX + userId;
        try {
            String sessionId = jedisClient.hget(key, field);
            if (StringUtils.isNotBlank(sessionId)) {
                webSocketServer.sendMessage(JsonUtils.objectToJson(resultVO), sessionId);
            } else {
                throw new Exception("session未找到");
            }
        } catch (Exception e) {
            log.error("接收通知消息错误,错误位置:{},错误信息:{}", "MQConsumer.receiveService()", e.getMessage());
        }
    }
}
 
Example 8
Source Project: paas   Source File: MQConsumer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 接收数据卷信息
 * @author hf
 * @since 2018/7/13 17:08
 */
@JmsListener(destination = "MQ_QUEUE_VOLUME")
public void receiveVolume(String text) {
    if (StringUtils.isNotBlank(text)) {
        Task task = JsonUtils.jsonToObject(text, Task.class);

        Map<String, String> map = task.getData();
        String userId = map.get("uid");
        ResultVO resultVO = JsonUtils.jsonToObject(map.get("data"), ResultVO.class);

        String field = ID_PREFIX + userId;
        try {
            String sessionId = jedisClient.hget(key, field);
            if (StringUtils.isNotBlank(sessionId)) {
                webSocketServer.sendMessage(JsonUtils.objectToJson(resultVO), sessionId);
            } else {
                throw new Exception("session未找到");
            }
        } catch (Exception e) {
            log.error("接收通知消息错误,错误位置:{},错误信息:{}", "MQConsumer.接收到消息()", e.getMessage());
        }
    }
}
 
Example 9
@JmsListener(destination = JMSType.SEND_MAIL)
public void sendMail(@Payload Object obj, @Headers MessageHeaders headers, Message message, Session session) {
	log.info("recived mail: {}", obj);

	System.out.println("-------------------------");
	System.out.println("obj:" + obj);
	System.out.println("headers:" + headers);
	System.out.println("message:" + message);
	System.out.println("session:" + session);
	System.out.println("-------------------------");

	if (obj instanceof MimeMessage) {
		mailSender.send((MimeMessage) obj);
	} else {
		mailSender.send((SimpleMailMessage) obj);
	}
}
 
Example 10
Source Project: spring-jms   Source File: Receiver.java    License: MIT License 6 votes vote down vote up
@JmsListener(destination = "${destination.order}")
public void receiveOrder(String orderNumber,
    @Header(JmsHeaders.MESSAGE_ID) String messageId) {
  LOGGER.info("received OrderNumber='{}' with MessageId='{}'",
      orderNumber, messageId);

  LOGGER.info("sending Status='Accepted' with CorrelationId='{}'",
      messageId);

  jmsTemplate.send(statusDestination, messageCreator -> {
    TextMessage message =
        messageCreator.createTextMessage("Accepted");
    message.setJMSCorrelationID(messageId);
    return message;
  });
}
 
Example 11
@JmsListener( destination = Topics.TRACKER_IMPORT_JOB_TOPIC_NAME, containerFactory = "jmsQueueListenerContainerFactory" )
public void consume( TextMessage message ) throws JMSException, JsonProcessingException
{
    String payload = message.getText();

    TrackerMessage trackerMessage = objectMapper.readValue( payload, TrackerMessage.class );
    TrackerImportParams trackerImportParams = trackerMessage.getTrackerImportParams();

    JobConfiguration jobConfiguration = new JobConfiguration(
        "",
        JobType.TRACKER_IMPORT_JOB,
        trackerImportParams.getUserId(),
        true
    );

    jobConfiguration.setUid( trackerMessage.getUid() );
    trackerImportParams.setJobConfiguration( jobConfiguration );

    TrackerImportThread trackerImportThread = trackerImportThreadFactory.getObject();
    trackerImportThread.setTrackerImportParams( trackerImportParams );

    schedulingManager.executeJob( trackerImportThread );
}
 
Example 12
@JmsListener( destination = Topics.TRACKER_IMPORT_NOTIFICATION_TOPIC_NAME, containerFactory = "jmsQueueListenerContainerFactory" )
public void consume( TextMessage message ) throws JMSException, IOException
{
    TrackerSideEffectDataBundle bundle = toBundle( message );

    if ( bundle == null )
    {
        return;
    }

    JobConfiguration jobConfiguration = new JobConfiguration( "", JobType.TRACKER_IMPORT_NOTIFICATION_JOB, bundle.getAccessedBy(), true );

    bundle.setJobConfiguration( jobConfiguration );

    TrackerNotificationThread notificationThread = trackerNotificationThreadObjectFactory.getObject();

    notificationThread.setSideEffectDataBundle( bundle );

    executeJob( notificationThread );
}
 
Example 13
@JmsListener( destination = Topics.TRACKER_IMPORT_RULE_ENGINE_TOPIC_NAME, containerFactory = "jmsQueueListenerContainerFactory" )
public void consume( TextMessage message ) throws JMSException, IOException
{
    TrackerSideEffectDataBundle bundle = toBundle( message );

    if ( bundle == null )
    {
        return;
    }

    JobConfiguration jobConfiguration = new JobConfiguration( "", JobType.TRACKER_IMPORT_RULE_ENGINE_JOB, bundle.getAccessedBy(), true );

    bundle.setJobConfiguration( jobConfiguration );

    TrackerRuleEngineThread notificationThread = trackerRuleEngineThreadObjectFactory.getObject();

    notificationThread.setSideEffectDataBundle( bundle );

    executeJob( notificationThread );
}
 
Example 14
Source Project: nimrod   Source File: MailServiceImpl.java    License: MIT License 5 votes vote down vote up
@JmsListener(destination = MAIL_QUEUE)
@Override
public void consume(String message) {
    MailEntity mailEntity = null;
    try {
        mailEntity = common.jsonToObject(message, MailEntity.class);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (mailEntity != null) {
        send(mailEntity);
    }
}
 
Example 15
Source Project: Spring   Source File: UserReceiver.java    License: Apache License 2.0 5 votes vote down vote up
@JmsListener(destination = "userQueue", containerFactory = "connectionFactory")
public void receiveMessage(User receivedUser, Message message) {
    log.info(" >> Original received message: " + message);
    log.info(" >> Received user: " + receivedUser);
    confirmationSender.sendMessage(new Confirmation(id.incrementAndGet(), "User " + receivedUser.getEmail() + " received."));

}
 
Example 16
Source Project: hdw-dubbo   Source File: ActiveMQReceiveMsgService.java    License: Apache License 2.0 5 votes vote down vote up
@JmsListener(destination = "ActiveMQ.Advisory.Consumer.Queue.test", containerFactory = "topicJmsListenerContainerFactory", concurrency = "5-10")
public void advisoryConsumerQueueTest3(Message msg) {
    try {
        if (msg instanceof ActiveMQMessage) {
            ActiveMQMessage aMsg = (ActiveMQMessage) msg;
            if (aMsg.getDataStructure() instanceof ConsumerInfo) {
                ConsumerInfo consumerInfo = (ConsumerInfo) aMsg.getDataStructure();
                log.info("sensorDataQueue消费者信息:" + JacksonUtil.toJson(consumerInfo));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 17
Source Project: hdw-dubbo   Source File: ActiveMQReceiveMsgService.java    License: Apache License 2.0 5 votes vote down vote up
@JmsListener(destination = "ActiveMQ.Advisory.Producer.Queue.test", containerFactory = "topicJmsListenerContainerFactory", concurrency = "5-10")
public void advisoryProducerQueueTest(Message msg) {
    try {
        if (msg instanceof ActiveMQMessage) {
            ActiveMQMessage aMsg = (ActiveMQMessage) msg;
            if (aMsg.getDataStructure() instanceof ProducerInfo) {
                ProducerInfo producerInfo = (ProducerInfo) aMsg.getDataStructure();
                log.info("sensorDataQueue生产者信息:" + JacksonUtil.toJson(producerInfo));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 18
Source Project: mq-jms-spring   Source File: Listener.java    License: Apache License 2.0 5 votes vote down vote up
@JmsListener(destination = Application.qName)
public void receiveMessage(String msg) {
  infinityWarning();

  System.out.println();
  System.out.println("========================================");
  System.out.println("Received message is: " + msg);
  System.out.println("========================================");

}
 
Example 19
Source Project: tutorial   Source File: SampleService.java    License: MIT License 5 votes vote down vote up
/**
 * JmsListener注解可以声明这个方法用于接收JMS(ActiveMQ)消息队列里的消息
 * @param message
 */
@JmsListener(destination="addtvseriesevents")
public void receiveMessage(String message) {
    if(log.isTraceEnabled()) {
        log.trace("Received <" + message + ">");
    }
}
 
Example 20
Source Project: k8s-fleetman   Source File: MessageProcessor.java    License: MIT License 5 votes vote down vote up
@JmsListener(destination="${fleetman.position.queue}")
public void processPositionMessageFromQueue(Map<String, String> incomingMessage ) throws ParseException 
{
	Date convertedDatestamp = new java.util.Date();
	
	VehiclePosition newReport = new VehicleBuilder()
			                          .withName(incomingMessage.get("vehicle"))
			                          .withLat(new BigDecimal(incomingMessage.get("lat")))
			                          .withLng(new BigDecimal(incomingMessage.get("long")))
			                          .withTimestamp(convertedDatestamp)
			                          .build();
			                          
	data.updatePosition(newReport);
}
 
Example 21
@JmsListener(destination = "${solace.jms.demoConsumerQueueJndiName}", containerFactory = "cFactory")
public void processMsg(Message<?> msg) {
	StringBuffer msgAsStr = new StringBuffer("============= Received \nHeaders:");
	MessageHeaders hdrs = msg.getHeaders();
	msgAsStr.append("\nUUID: " + hdrs.getId());
	msgAsStr.append("\nTimestamp: " + hdrs.getTimestamp());
	Iterator<String> keyIter = hdrs.keySet().iterator();
	while (keyIter.hasNext()) {
		String key = keyIter.next();
		msgAsStr.append("\n" + key + ": " + hdrs.get(key));
	}
	msgAsStr.append("\nPayload: " + msg.getPayload());
	logger.info(msgAsStr.toString());
}
 
Example 22
Source Project: seckill   Source File: SpringSecKillMessageSubscriber.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@JmsListener(destination = "seckill", containerFactory = "containerFactory")
public void subscribeMessage(String messageContent) {
  logger.info("receive message : {}", messageContent);
  EventMessageDto message = eventFormat.getFormat().deserialize(messageContent, EventMessageDto.class);
  SecKillEvent event = eventFormat.fromMessage(message);
  eventFactories.get(event.getType()).accept(event);
}
 
Example 23
Source Project: MyBlog   Source File: MqListener.java    License: Apache License 2.0 5 votes vote down vote up
@JmsListener(destination = "com.lfz.queue.mail", containerFactory = "queueFactory")
public void onQueueMessage(String username) {
    try {
        log.info("new user:{}", username);
        myMailSender.send(username);
    } catch (Exception e) {
        log.error("on queue message error", e);
    }
}
 
Example 24
Source Project: MyBlog   Source File: MqListener.java    License: Apache License 2.0 5 votes vote down vote up
@JmsListener(destination = "com.lfz.topic.ws", containerFactory = "topicFactory")
public void onTopicMessage(String message) {
    try {
        wsHandler.sendAllUser(message);
    } catch (Exception e) {
        log.error("on topic message error", e);
    }
}
 
Example 25
Source Project: myth   Source File: ActivemqConsumer.java    License: Apache License 2.0 5 votes vote down vote up
@JmsListener(destination = "account",containerFactory = "queueListenerContainerFactory")
public void receiveQueue(byte[] message) {
    LOGGER.info("=========扣减账户信息接收到Myth框架传入的信息==========");
    final Boolean success = mythMqReceiveService.processMessage(message);
    if(success){
        //消费成功,消息出队列,否则不消费
    }
}
 
Example 26
Source Project: myth   Source File: ActivemqConsumer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Receive queue.
 *
 * @param message the message
 */
@JmsListener(destination = "inventory", containerFactory = "queueListenerContainerFactory")
public void receiveQueue(byte[] message) {
    LOGGER.info("=========motan扣减库存接收到Myth框架传入的信息==========");
    mythMqReceiveService.processMessage(message);

}
 
Example 27
Source Project: myth   Source File: ActivemqConsumer.java    License: Apache License 2.0 5 votes vote down vote up
@JmsListener(destination = "account",containerFactory = "queueListenerContainerFactory")
public void receiveQueue(byte[] message) {
    LOGGER.info("=========扣减账户信息接收到Myth框架传入的信息==========");
    final Boolean success = mythMqReceiveService.processMessage(message);
    if(success){
        //消费成功,消息出队列,否则不消费
    }
}
 
Example 28
Source Project: myth   Source File: ActivemqConsumer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Receive queue.
 *
 * @param message the message
 */
@JmsListener(destination = "account",containerFactory = "queueListenerContainerFactory")
public void receiveQueue(byte[] message) {
    LOGGER.info("=========扣减账户信息接收到Myth框架传入的信息==========");
    final Boolean success = mythMqReceiveService.processMessage(message);
    if(success){
        //消费成功,消息出队列,否则不消费
    }
}
 
Example 29
Source Project: myth   Source File: ActivemqConsumer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Receive queue.
 *
 * @param message the message
 */
@JmsListener(destination = "inventory", containerFactory = "queueListenerContainerFactory")
public void receiveQueue(byte[] message) {
    LOGGER.info("=========扣减库存接收到Myth框架传入的信息==========");
    mythMqReceiveService.processMessage(message);

}
 
Example 30
Source Project: ditto-examples   Source File: MessageConsumer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@JmsListener(destination = "dittooutbound/Subscriptions/fromditto",
    containerFactory = "myFactory")
public void processDittoMessage(final String message) {

  final JsonValue jsonValue = JsonFactory.readFrom(message);
  final Adaptable adaptable = ProtocolFactory.jsonifiableAdaptableFromJson(jsonValue.asObject());

  final Signal<?> actual = DITTO_PROTOCOL_ADAPTER.fromAdaptable(adaptable);

  System.out.println("Got signal from Ditto: " + actual);
}