@Override
  @Transactional("jmsTxManager")
  @CacheEvict(
      value = {"fixedDepositList"},
      allEntries = true,
      beforeInvocation = true)
  public void createFixedDeposit(final FixedDepositDetails fdd) throws Exception {
    logger.info("createFixedDeposit method invoked");
    jmsTemplate.send(
        "emailQueueDestination",
        new MessageCreator() {
          @Override
          public Message createMessage(Session session) throws JMSException {
            TextMessage textMessage = session.createTextMessage();
            textMessage.setText(fdd.getEmail());
            return textMessage;
          }
        });

    // --this JMS message goes to the default destination configured for the
    // JmsTemplate
    jmsTemplate.send(
        new MessageCreator() {
          @Override
          public Message createMessage(Session session) throws JMSException {
            ObjectMessage objectMessage = session.createObjectMessage();
            objectMessage.setObject(fdd);
            return objectMessage;
          }
        });
  }
  /** Generates JMS messages */
  public void generateAndSendMessages(final CacheFlushMessageJms cacheFlushMessageJms) {
    try {
      final String valueJMSMessage =
          xmlMapper.getXmlMapper().writeValueAsString(cacheFlushMessageJms);

      if (StringUtils.isNotEmpty(valueJMSMessage)) {
        jmsTemplate.send(
            new MessageCreator() {
              public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage(valueJMSMessage);
                if (logger.isDebugEnabled()) {
                  logger.info("Sending JMS message: " + valueJMSMessage);
                }
                return message;
              }
            });
      } else {
        logger.warn("Cache Flush Message Jms Message is empty");
      }

    } catch (JmsException e) {
      logger.error("Exception during create/send message process");
    } catch (JsonProcessingException e) {
      logger.error("Exception during build message process");
    }
  }
示例#3
0
 @Override
 protected void sendMessage(
     MessageSendingInfo<Destination, InternalMessageType> messageSendingInfo) {
   Destination destination = messageSendingInfo.messageDetails.destination;
   MessageCreator outgoingMessageCreator = createJmsMessageCreator(messageSendingInfo);
   jmsTemplate.send(destination, outgoingMessageCreator);
 }
  public static void main(String[] args) {
    ClassPathXmlApplicationContext context =
        new ClassPathXmlApplicationContext("classpath:integration-transformer.xml");

    JmsTemplate jmsTemplate = context.getBean("jmsTemplate", JmsTemplate.class);

    jmsTemplate.send(
        new MessageCreator() {

          @Override
          public javax.jms.Message createMessage(Session session) throws JMSException {
            MapMessage message = session.createMapMessage();
            message.setString("firstName", "John");
            message.setString("lastName", "Smith");
            message.setString("address", "100 State Street");
            message.setString("city", "Los Angeles");
            message.setString("state", "CA");
            message.setString("zip", "90064");
            System.out.println("Sending message: " + message);
            return message;
          }
        });

    PollableChannel output = (PollableChannel) context.getBean("output");
    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
  }
  @Test
  public void testWithReply() throws Exception {
    QueueChannel replies = new QueueChannel();
    this.gateway1.setOutputChannel(replies);
    this.gateway1.start();
    this.gateway1.handleMessage(
        MessageBuilder.withPayload("foo")
            .setHeader(
                JmsHeaders.CORRELATION_ID,
                "baz") // make sure it's restored in case we're from an upstream gw
            .build());
    JmsTemplate template = new JmsTemplate(this.ccf);
    template.setReceiveTimeout(10000);
    final Message received = template.receive("asyncTest1");
    assertNotNull(received);
    template.send(
        received.getJMSReplyTo(),
        new MessageCreator() {

          @Override
          public Message createMessage(Session session) throws JMSException {
            TextMessage textMessage = session.createTextMessage("bar");
            textMessage.setJMSCorrelationID(received.getJMSCorrelationID());
            return textMessage;
          }
        });
    org.springframework.messaging.Message<?> reply = replies.receive(10000);
    assertNotNull(reply);
    assertEquals("bar", reply.getPayload());
    assertEquals("baz", reply.getHeaders().get(JmsHeaders.CORRELATION_ID));
    this.gateway1.stop();
  }
示例#6
0
  public void sendObject(
      Destination destination, final Serializable object, final String type, final String value) {
    try {
      jmsTemplate.send(
          destination,
          new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
              ObjectMessage objectMessage = session.createObjectMessage(object);
              objectMessage.setStringProperty(type, value);
              return objectMessage;
            }
          });

    } catch (Exception e) {
      logger.debug("消息发送失败" + destination.toString() + ":" + object);
      e.printStackTrace();
      FailedJms failedJms = new FailedJms();
      failedJms.setId(ObjectId.get());
      failedJms.setDestination(destination);
      failedJms.setMessage(object);
      failedJms.setFailedTime(new Date());
      Map<String, String> properties = new HashMap<String, String>();
      properties.put(type, value);
      failedJms.setProperties(properties);
      saveFailedJms(failedJms);
    }
  }
  public void pushEvents(IPatientObject item) {
    List<PatientEvent<IPatientObject>> events = item.getEvents();
    if (events == null || events.size() == 0) {
      return;
    }

    for (final PatientEvent<IPatientObject> evt : events) {
      jms.send(
          QUEUE_NAME,
          new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
              Message msg = session.createObjectMessage(evt);
              IPatientObject obj = evt.getSource();
              msg.setStringProperty("uid", obj.getUid());
              msg.setStringProperty("pid", obj.getPid());
              msg.setStringProperty("type", evt.getType().toString());
              msg.setStringProperty("summary", obj.getSummary());
              //					msg.setJMSCorrelationID(arg0)
              //					msg.setJMSDeliveryMode(arg0)
              //					msg.setJMSType(arg0)
              return msg;
            }
          });
    }
  }
示例#8
0
  protected void sendEvent(
      final Stock stock,
      final String eventListName,
      final EventValue event,
      final EmailFilterEventSource eventSource,
      final EventInfo eventInfo) {

    if (AnalysisClient.getEmailMsgQeueingFilter().contains(eventSource)) {
      jmsTemplate.send(
          eventQueue,
          new MessageCreator() {

            public Message createMessage(Session session) throws JMSException {

              SingleEventMessage message =
                  new SingleEventMessage(
                      eventListName, endDate, stock, event, ConfigThreadLocal.getAll());
              message.setObjectProperty(
                  MessageProperties.ANALYSE_SOURCE.getKey(), eventSource); // Source
              message.setObjectProperty(
                  MessageProperties.TREND.getKey(),
                  event.getEventType().name()); // Bearish or Bullish or Other?
              message.setObjectProperty(MessageProperties.SEND_EMAIL.getKey(), Boolean.TRUE);
              if (eventInfo != null)
                message.setObjectProperty(
                    MessageProperties.EVENT_INFO.getKey(), eventInfo.getEventReadableDef());

              return message;
            }
          });
    }
  }
 private void receiveAndSend(JmsTemplate template) {
   javax.jms.Message request = template.receive(requestQueue7);
   final javax.jms.Message jmsReply = request;
   try {
     template.send(request.getJMSReplyTo(), (MessageCreator) session -> jmsReply);
   } catch (JmsException | JMSException e) {
   }
 }
 /**
  * 发送
  *
  * @param test
  */
 public void sendMessage(final String test) {
   jmsTemplate.send(
       DEFAULT_ActiveMQQueue,
       new MessageCreator() {
         @Override
         public Message createMessage(Session session) throws JMSException {
           return session.createTextMessage(test);
         }
       });
 }
示例#11
0
 public void send(final String message, String queueName) {
   MessageCreator messageCreator =
       new MessageCreator() {
         @Override
         public Message createMessage(Session session) throws JMSException {
           return session.createTextMessage(message);
         }
       };
   jmsTemplate.send(queueName, messageCreator);
 }
示例#12
0
 public void updateComment(final List<Integer> msgids) {
   jmsTemplate.send(
       queue,
       new MessageCreator() {
         @Override
         public Message createMessage(Session session) throws JMSException {
           return session.createObjectMessage(new UpdateComments(msgids));
         }
       });
 }
 @Override
 public void registerMerchantAsyncronously(final Merchant merchant) {
   jmsTemplate.send(
       new MessageCreator() {
         @Override
         public Message createMessage(Session session) throws JMSException {
           return session.createObjectMessage(merchant);
         }
       });
 }
 public void sendMessage(Destination destination, final String message) {
   System.out.println("--------------生产者产生一个消息--------------");
   System.out.println("生产者发送一个消息:" + message);
   jmsTemplate.send(
       destination,
       new MessageCreator() {
         public Message createMessage(Session session) throws JMSException {
           return session.createTextMessage(message);
         }
       });
 }
示例#15
0
 public void send(String target) {
   MessageCreator messageCreator =
       new MessageCreator() {
         @Override
         public Message createMessage(Session session) throws JMSException {
           return session.createTextMessage("test");
         }
       };
   JmsTemplate jmsTemplate = AppRun.getContext().getBean(JmsTemplate.class);
   jmsTemplate.send(target, messageCreator);
 }
示例#16
0
 public void send(final Serializable object, Destination destination) {
   jmsTemplate.send(
       destination,
       new MessageCreator() {
         public ObjectMessage createMessage(Session session) throws JMSException {
           ObjectMessage message = session.createObjectMessage(object);
           message.setIntProperty("attempt", 1);
           return message;
         }
       });
 }
示例#17
0
 private void sendMessage(Object msg) {
   try {
     final String text = converter.toXML(msg);
     MessageCreator creator = session -> session.createTextMessage(text);
     JmsTemplate template = context.getBean(JmsTemplate.class);
     template.setConnectionFactory(connectionFactory);
     template.send(serverQueue, creator);
   } catch (Exception e) {
     log.warn("Exception " + e.toString() + " sending message - ignoring");
   }
 }
 @Override
 public void send(final Message message) {
   jmsTemplate.send(
       queue,
       new MessageCreator() {
         @Override
         public javax.jms.Message createMessage(Session session) throws JMSException {
           return messageConverter.toMessage(message, session);
         }
       });
 }
示例#19
0
  public void updateMonth(final int year, final int month) {
    logger.info("Scheduling reindex by date " + year + '/' + month);

    jmsTemplate.send(
        queue,
        new MessageCreator() {
          @Override
          public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage(new UpdateMonth(year, month));
          }
        });
  }
示例#20
0
  public void updateMessage(final int msgid, final boolean withComments) {
    logger.info("Scheduling reindex #" + msgid + " withComments=" + withComments);

    jmsTemplate.send(
        queue,
        new MessageCreator() {
          @Override
          public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage(new UpdateMessage(msgid, withComments));
          }
        });
  }
示例#21
0
  public void updateComment(final int msgid) {
    Preconditions.checkArgument(msgid != 0, "msgid==0!?");

    jmsTemplate.send(
        queue,
        new MessageCreator() {
          @Override
          public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage(
                new UpdateComments(Collections.singletonList(msgid)));
          }
        });
  }
示例#22
0
 public void reSendObject(
     Destination destination, final Serializable object, final String type, final String value) {
   jmsTemplate.send(
       destination,
       new MessageCreator() {
         @Override
         public Message createMessage(Session session) throws JMSException {
           ObjectMessage objectMessage = session.createObjectMessage(object);
           objectMessage.setStringProperty(type, value);
           return objectMessage;
         }
       });
 }
示例#23
0
 public static void main(String[] args) {
   ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
   JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate");
   jmsTemplate.send(
       new MessageCreator() {
         public ObjectMessage createMessage(Session session) throws JMSException {
           ObjectMessage message = session.createObjectMessage();
           message.setObject("My first Message");
           return message;
         }
       });
   System.out.println("MESSAGE SENT TO myMessageQueue");
 }
  @Test
  public void testContainerWithDestNameNoCorrelation() throws Exception {
    BeanFactory beanFactory = mock(BeanFactory.class);
    when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME))
        .thenReturn(true);
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.initialize();
    when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class))
        .thenReturn(scheduler);
    final JmsOutboundGateway gateway = new JmsOutboundGateway();
    gateway.setBeanFactory(beanFactory);
    gateway.setConnectionFactory(getConnectionFactory());
    gateway.setRequestDestination(requestQueue4);
    gateway.setReplyDestinationName("reply4");
    gateway.setUseReplyContainer(true);
    gateway.afterPropertiesSet();
    gateway.start();
    final AtomicReference<Object> reply = new AtomicReference<Object>();
    final CountDownLatch latch1 = new CountDownLatch(1);
    final CountDownLatch latch2 = new CountDownLatch(1);
    Executors.newSingleThreadExecutor()
        .execute(
            () -> {
              latch1.countDown();
              try {
                reply.set(gateway.handleRequestMessage(new GenericMessage<String>("foo")));
              } finally {
                latch2.countDown();
              }
            });
    assertTrue(latch1.await(10, TimeUnit.SECONDS));
    JmsTemplate template = new JmsTemplate();
    template.setConnectionFactory(getConnectionFactory());
    template.setReceiveTimeout(10000);
    javax.jms.Message request = template.receive(requestQueue4);
    assertNotNull(request);
    final javax.jms.Message jmsReply = request;
    template.send(
        request.getJMSReplyTo(),
        (MessageCreator)
            session -> {
              jmsReply.setJMSCorrelationID(jmsReply.getJMSMessageID());
              return jmsReply;
            });
    assertTrue(latch2.await(10, TimeUnit.SECONDS));
    assertNotNull(reply.get());

    gateway.stop();
    scheduler.destroy();
  }
 public static void main(String[] args) {
   @SuppressWarnings("resource")
   ApplicationContext ctx = new ClassPathXmlApplicationContext("/beans.xml");
   JmsTemplate template = (JmsTemplate) ctx.getBean("jmsTemplate");
   Destination destination = (Destination) ctx.getBean("sessionAwareQueueDestination");
   template.send(
       destination,
       new MessageCreator() {
         public Message createMessage(Session session) throws JMSException {
           return session.createTextMessage("Send the message for the SessionAwareQueue test");
         }
       });
   System.out.println("JMS Message Sent");
 }
  public void sendMessage(
      final Long merchantId, final String merchantProdCode, final String status, final long delay) {
    jmsTemplate.send(
        new MessageCreator() {
          public Message createMessage(Session session) throws JMSException {
            MapMessage message = session.createMapMessage();
            message.setLong("merchantId", merchantId);
            message.setString("merchantProdCode", merchantProdCode);
            message.setString("status", status);

            message.setLongProperty(
                ScheduledMessage.AMQ_SCHEDULED_DELAY, delay > 0 ? delay : 10000);
            return message;
          }
        });
  }
  public void generateMessages() throws JMSException {
    for (int i = 0; i < messageCount; i++) {
      final int index = i;
      final String text = "Message number is " + i + ".";

      template.send(
          new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
              TextMessage message = session.createTextMessage(text);
              message.setIntProperty(MESSAGE_COUNT, index);

              return message;
            }
          });
    }
  }
  public void sendScheduledMessage(final String message) {
    jmsTemplate.send(
        SCHEDULED_QUEUE,
        new MessageCreator() {
          @Override
          public Message createMessage(Session session) throws JMSException {
            System.out.println("Scheduling message.");
            LocalDateTime data = LocalDateTime.now().plusSeconds(10);
            long delay = 60 * 1000;

            TextMessage messageToSend = session.createTextMessage(message);
            messageToSend.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
            return messageToSend;
          }
        });
  }
 /**
  * Generates JMS messages
  *
  * @throws UnsupportedEncodingException
  */
 public void generateMessages() throws JMSException, UnsupportedEncodingException {
   try {
     final String valueJMSMessage = "message JMS";
     jmsTemplate.send(
         new MessageCreator() {
           public Message createMessage(Session session) throws JMSException {
             TextMessage message = session.createTextMessage(valueJMSMessage);
             if (logger.isDebugEnabled()) {
               logger.info("Sending JMS message: " + valueJMSMessage);
             }
             return message;
           }
         });
   } catch (Exception e) {
     logger.error("Exception during create/send message process");
   }
 }
示例#30
0
  private void sendBusPosition(
      String line, String id, float latitude, float longitude, int orientation) {

    jmsTemplate.send(
        getDestination(),
        new MessageCreator() {
          @Override
          public Message createMessage(Session session) throws JMSException {
            Message buspos = session.createMessage();
            buspos.setStringProperty(LINE_PROPERTY, line);
            buspos.setStringProperty(NUMBERPLATE_PROPERTY, id);
            buspos.setFloatProperty(LATITUDE_PROPERTY, latitude);
            buspos.setFloatProperty(LONGITUDE_PROPERTY, longitude);
            buspos.setIntProperty(ORIENTATION_PROPERTY, orientation);
            return buspos;
          }
        });
  }