本文整理匯總了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;
}
});
}
示例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;
}
});
}
示例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;
}
});
}
}
示例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();
}
}
示例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);
}
示例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;
}
});
}
示例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();
}
}
示例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());
}
示例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;
}
});
}
示例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;
}
}
示例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();
}
}
}
示例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");}
}
示例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();
}
}
示例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;
}
});
}
示例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;
}