當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageCreator類代碼示例

本文整理匯總了Java中org.springframework.jms.core.MessageCreator的典型用法代碼示例。如果您正苦於以下問題:Java MessageCreator類的具體用法?Java MessageCreator怎麽用?Java MessageCreator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MessageCreator類屬於org.springframework.jms.core包,在下文中一共展示了MessageCreator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendMessage

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
/**
 * 使用jmsTemplate的send/MessageCreator()發送Map類型的消息並在Message中附加屬性用於消息過濾.
 */
private void sendMessage(final User user, Destination destination) {
	jmsTemplate.send(destination, new MessageCreator() {
		@Override
		public Message createMessage(Session session) throws JMSException {

			MapMessage message = session.createMapMessage();
			message.setString("userName", user.getName());
			message.setString("email", user.getEmail());

			message.setStringProperty("objectType", "user");

			return message;
		}
	});
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:19,代碼來源:AdvancedNotifyMessageProducer.java

示例2: sendMessage

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
@Override
public void sendMessage(final Message message) {
	this.jmsTemplate.send(createDestination(message.getDestination()), new MessageCreator() {
		@Override
		public javax.jms.Message createMessage(Session session) throws JMSException {
			BytesMessage bytesMessage = session.createBytesMessage();
			bytesMessage.writeBytes(message.getBody());
			if(!CollectionUtils.isEmpty(message.getProperties())){
				if(message.getProperties().get("JMSXGroupID") != null){
					bytesMessage.setStringProperty("JMSXGroupID", message.getProperties().get("JMSXGroupID").toString());
				}
				if(message.getProperties().get("JMSXGroupSeq") != null){
					String JMSXGroupSeq = message.getProperties().get("JMSXGroupSeq").toString();
					if(StringUtil.isNumeric(JMSXGroupSeq)){
						bytesMessage.setIntProperty("JMSXGroupSeq", Integer.valueOf(JMSXGroupSeq));
					}
				}
			}
			return bytesMessage;
		}
	});
}
 
開發者ID:yanghuijava,項目名稱:elephant,代碼行數:23,代碼來源:ActivemqProducerService.java

示例3: generateMessages

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
/**
 * Generates JMS messages
 */
@PostConstruct
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);
                
                System.out.println("Sending message: " + text);
                
                return message;
            }
        });
    }
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:22,代碼來源:JmsMessageProducer.java

示例4: validateFailOnUnsupportedMessageTypeOverJNDI

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
public void validateFailOnUnsupportedMessageTypeOverJNDI() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage();
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    try {
        consumer.consume(destinationName, new ConsumerCallback() {
            @Override
            public void accept(JMSResponse response) {
                // noop
            }
        });
    } finally {
        ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
    }
}
 
開發者ID:lsac,項目名稱:nifi-jms-jndi,代碼行數:24,代碼來源:JMSPublisherConsumerTest.java

示例5: main

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
public static void main(String[] args) throws Exception {


        ApplicationContext ctx = new ClassPathXmlApplicationContext(
          "com/springtraining/jms/JmsTemplateTest-context.xml");
        JmsTemplate template = (JmsTemplate) ctx.getBean("jmsTemplate");
        
       // for(int i=0; i<10; i++) {
            template.send("SpringSendTestQueue", new MessageCreator() {
                public Message createMessage(Session session)
                    throws JMSException {
                    TextMessage tm = session.createTextMessage();
                    tm.setText("This is a spring test message");
                    return tm;
                }
            });
            System.out.println("Message sent");
       // }
        System.exit(1);
    }
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:21,代碼來源:JmsTemplateTest.java

示例6: run

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
@Override
public void run(String... strings) throws Exception {
    final String messageText = "Hello World";
    LOG.info("============= Sending " + messageText);
    this.jmsTemplate.send("example", new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            Queue replyQueue = session.createQueue("reply-queue");

            TextMessage message = session.createTextMessage(messageText);

            message.setJMSCorrelationID(correlationID.toString());
            message.setJMSReplyTo(replyQueue);

            return message;
        }
    });
}
 
開發者ID:tabish121,項目名稱:qpid-jms-spring-boot,代碼行數:20,代碼來源:Requestor.java

示例7: validateFailOnUnsupportedMessageType

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
/**
 * At the moment the only two supported message types are TextMessage and
 * BytesMessage which is sufficient for the type if JMS use cases NiFi is
 * used. The may change to the point where all message types are supported
 * at which point this test will no be longer required.
 */
@Test(expected = IllegalStateException.class)
public void validateFailOnUnsupportedMessageType() throws Exception {
    final String destinationName = "testQueue";
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);

    jmsTemplate.send(destinationName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createObjectMessage();
        }
    });

    JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class));
    try {
        consumer.consume(destinationName, new ConsumerCallback() {
            @Override
            public void accept(JMSResponse response) {
                // noop
            }
        });
    } finally {
        ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
    }
}
 
開發者ID:SolaceLabs,項目名稱:solace-integration-guides,代碼行數:31,代碼來源:JMSPublisherConsumerTest.java

示例8: sendAndReceive

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
@Test
public void sendAndReceive() throws Exception {
  jmsTemplate.send("TEST.FOO", new MessageCreator() {
    @Override
    public Message createMessage(Session session) throws JMSException {
      return session.createTextMessage("Hello world");
    }
  });

  TextMessage received = (TextMessage) jmsTemplate.receive("TEST.FOO");
  assertEquals("Hello world", received.getText());

  jmsTemplate.convertAndSend("TEST.FOO", "Hello world");
  assertEquals("Hello world", jmsTemplate.receiveAndConvert("TEST.FOO"));

  List<MockSpan> mockSpans = mockTracer.finishedSpans();
  assertEquals(4, mockSpans.size());

  checkSpans(mockSpans);
  assertNull(mockTracer.activeSpan());
}
 
開發者ID:opentracing-contrib,項目名稱:java-jms,代碼行數:22,代碼來源:TracingJmsTemplateTest.java

示例9: run

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
@Override
public void run(String... strings) throws Exception {
    final String messageText = "Request";
    LOG.info("============= Sending: " + messageText);
    this.jmsTemplate.send("example", new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            Queue replyQueue = session.createQueue("reply-queue");

            TextMessage message = session.createTextMessage(messageText);

            message.setJMSCorrelationID(correlationID.toString());
            message.setJMSReplyTo(replyQueue);

            return message;
        }
    });
}
 
開發者ID:amqphub,項目名稱:amqp-10-jms-spring-boot,代碼行數:20,代碼來源:Requestor.java

示例10: verstuurBijhoudingsNotificatie

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
@Override
public void verstuurBijhoudingsNotificatie(final BijhoudingsplanNotificatieBericht notificatieBericht) {
    try {
        final MessageCreator messageCreator = session -> {
            final TextMessage message = session.createTextMessage();
            // Header voor message group mechanisme van ActiveMq
            message.setStringProperty("JMSXGroupID", String.valueOf(notificatieBericht.getOntvangendePartijCode()));
            message.setText(serialiseerderBijhoudingsplan.serialiseerNaarString(notificatieBericht));
            return message;
        };
        bijhoudingsplanJmsTemplate.send(messageCreator);
    } catch (final JmsException e) {
        LOGGER.error("Het publiceren van het verwerk BijhoudingsplanBericht is mislukt ivm een JMS exceptie.", e);
        throw e;
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:17,代碼來源:MutatieNotificatieServiceImpl.java

示例11: onMessage

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
@Override
public void onMessage(Message message) {
    if(message instanceof TextMessage) {
        TextMessage textMessage = (TextMessage) message;
        try {
            final String request = textMessage.getText();
            Destination destination = textMessage.getJMSReplyTo();
            final String jmsCorrelationId = textMessage.getJMSCorrelationID();
            jmsTemplate.send(destination, new MessageCreator() {
                @Override
                public Message createMessage(Session session) throws JMSException {
                    Message createdMessage = session.createTextMessage(request + "'s reply!");
                    createdMessage.setJMSCorrelationID(jmsCorrelationId);
                    return createdMessage;
                }
            });
        } catch (JMSException ex) {
            ex.printStackTrace();
        }
    }
}
 
開發者ID:xitongjiagoushi,項目名稱:spring-activemq,代碼行數:22,代碼來源:Consumer.java

示例12: run

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
@Override
public void run(String... arg0) throws Exception {
	if(jmsTemplate != null) {
		
		log.info("Sending "+numMessages+" messages with payload "+message+" and delay of "+delay);
		if(size > 0) {
			//Upscale the message to the right size
			int messageLength = message.length();
			char[] charArray = new char[size*1000];
			Arrays.fill(charArray, 'X');
			message = new String(charArray);
		}

		// Coerce a javax.jms.MessageCreator
		MessageCreator messageCreator = (Session session) -> {
			return session.createTextMessage(message);
		};

		// And publish to a RabbitMQ Queue using Spring's JmsTemplate
		for(int c=0; c<numMessages; c++) {
			jmsTemplate.send(queueName, messageCreator);
			Thread.sleep(delay);
		}
	}
	else {System.out.println("jmsTemplate is null");}
}
 
開發者ID:sdeeg-pivotal,項目名稱:rabbitmq-jms-samples,代碼行數:27,代碼來源:SpringRabbitJMSSender.java

示例13: historyDataGenerated

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
@Override
public void historyDataGenerated(List<ObjectNode> historyObjectNodes) {
    try {
        final String msg = objectMapper.writeValueAsString(historyObjectNodes);
        jmsTemplate.send(new MessageCreator() {
            
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage(msg);
            }
            
        });
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
}
 
開發者ID:flowable,項目名稱:flowable-examples,代碼行數:17,代碼來源:JmsAsyncHistoryListener.java

示例14: SendMessage

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
@Override
public void SendMessage(Destination destination, final byte[] message) {
  jmsTemplate.send(destination, new MessageCreator() {
    public Message createMessage(Session session) {
      BytesMessage msg;

      try {
        msg = session.createBytesMessage();
        msg.writeBytes(message);
        log.debug("報文發送完成");
      } catch (JMSException e) {
        throw JmsUtils.convertJmsAccessException(e);
      }
      return msg;
    }
  });
}
 
開發者ID:ibankapp,項目名稱:ibankapp-base,代碼行數:18,代碼來源:JmsCoreService.java

示例15: doSendToDestination

import org.springframework.jms.core.MessageCreator; //導入依賴的package包/類
private Object doSendToDestination(final Destination destination,
                                   final MessageCreator messageCreator,
                                   final MessageSentCallback callback,
                                   final Session session) throws JMSException {

    Assert.notNull(messageCreator, "MessageCreator must not be null");
    MessageProducer producer = createProducer(session, destination);
    Message message;
    try {
        message = messageCreator.createMessage(session);
        doSend(producer, message);
        if (message != null && callback != null) {
            callback.sent(session, message, destination);
        }
        // Check commit - avoid commit call within a JTA transaction.
        if (session.getTransacted() && isSessionLocallyTransacted(session)) {
            // Transacted session created by this template -> commit.
            JmsUtils.commitIfNecessary(session);
        }
    } finally {
        JmsUtils.closeMessageProducer(producer);
    }
    return null;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:25,代碼來源:JmsConfiguration.java


注:本文中的org.springframework.jms.core.MessageCreator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。