本文整理汇总了Java中org.springframework.integration.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于org.springframework.integration包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import org.springframework.integration.Message; //导入依赖的package包/类
/**
* @param message
* @throws Exception
*/
public void handle(Message<?> message, MessageChannel channel, Boolean sent) {
if(message != null) {
logger.info("Got a message:");
logger.info(message.toString());
messages.add(message);
logger.info("The Payload was:");
try {
logger.info(message.getPayload().toString() + ":" + BeanUtils.describe(message.getPayload()));
} catch (Exception e) {
logger.error("Error trying to describe the payload.", e);
}
logger.info("There are now " + messages.size() + " messages.");
} else {
logger.info("Got a null message.");
}
/*if(channel != null) {
logger.info("With channel: " + channel);
if(channel.equals(primaryChannel)) {
messages.add(message);
}
}*/
}
示例2: doSend
import org.springframework.integration.Message; //导入依赖的package包/类
protected boolean doSend(Message<?> message, long timeout) {
Assert.notNull(message, "'message' must not be null");
try {
if (timeout > 0) {
return this.queue
.offer(message, timeout, TimeUnit.MILLISECONDS);
}
if (timeout == 0) {
return this.queue.offer(message);
}
queue.put(message);
return true;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
}
示例3: run
import org.springframework.integration.Message; //导入依赖的package包/类
@Override
public void run() {
while (messageLoop) {
final Message<?> message = sqsExecutor.poll();
if (message != null) {
try {
workerThreadPool.execute(new Runnable() {
@Override
public void run() {
sendMessage(message);
sqsExecutor.acknowlegdeReceipt(message);
log.debug("Message sent...");
}
});
} catch (Throwable t) {
log.warn(t.getMessage(), t);
}
}
}
}
示例4: receive
import org.springframework.integration.Message; //导入依赖的package包/类
@Override
public Message<Object> receive() {
Message<Object> message = null;
Message<?> incoming = null;
try {
incoming = sqsExecutor.poll();
} catch (Throwable t) {
log.warn(t.getMessage(), t);
}
if (incoming != null) {
Object payload = incoming.getPayload();
final Message<?> callBackRef = incoming;
message = MessageBuilder.withPayload(payload)
.copyHeaders(incoming.getHeaders())
.setHeader(SqsHeaders.ACK_CALLBACK, new Callable<String>() {
@Override
public String call() throws Exception {
return sqsExecutor.acknowlegdeReceipt(callBackRef);
}
}).build();
}
return message;
}
示例5: run
import org.springframework.integration.Message; //导入依赖的package包/类
@Override
public void run() {
while (messageLoop) {
final Message<?> message = sqsExecutor.poll();
if (message != null) {
workerThreadPool.execute(new Runnable() {
@Override
public void run() {
try {
dispatcher.dispatch(message);
sqsExecutor.acknowlegdeReceipt(message);
log.debug("Message dispatched...");
} catch (Throwable t) {
log.warn(t.getMessage(), t);
}
}
});
}
}
}
示例6: receive
import org.springframework.integration.Message; //导入依赖的package包/类
@Override
public Message<?> receive(long timeout) {
Message<?> message = null;
Message<?> incoming = null;
try {
if (timeout > 0) {
incoming = sqsExecutor.poll(timeout);
} else {
incoming = sqsExecutor.poll();
}
} catch (Throwable t) {
log.warn(t.getMessage(), t);
}
if (incoming != null) {
final Message<?> callBackRef = incoming;
message = MessageBuilder.fromMessage(incoming)
.setHeader(SqsHeaders.ACK_CALLBACK, new Callable<String>() {
@Override
public String call() throws Exception {
return sqsExecutor.acknowlegdeReceipt(callBackRef);
}
}).build();
}
return message;
}
示例7: executeOutboundOperation
import org.springframework.integration.Message; //导入依赖的package包/类
/**
* Executes the outbound Sqs Operation.
*
*/
public Object executeOutboundOperation(final Message<?> message) {
try {
String serializedMessage = messageMarshaller.serialize(message);
if (queue == null) {
SendMessageRequest request = new SendMessageRequest(queueUrl,
serializedMessage);
SendMessageResult result = sqsClient.sendMessage(request);
log.debug("Message sent, Id:" + result.getMessageId());
} else {
queue.add(serializedMessage);
}
} catch (MessageMarshallerException e) {
log.error(e.getMessage(), e);
throw new MessagingException(e.getMessage(), e.getCause());
}
return message.getPayload();
}
示例8: onInit
import org.springframework.integration.Message; //导入依赖的package包/类
/**
* Check for mandatory attributes
*/
@Override
protected void onInit() {
super.onInit();
Assert.notNull(snsExecutor, "snsExecutor must not be null.");
this.notificationHandler = new NotificationHandler() {
@Override
protected void dispatch(Message<?> message) {
sendMessage(message);
}
};
log.info("SNS inbound adapter: [" + getComponentName()
+ "], initialized...");
}
示例9: executeOutboundOperation
import org.springframework.integration.Message; //导入依赖的package包/类
/**
* Executes the outbound Sns Operation.
*
*/
public Object executeOutboundOperation(final Message<?> message) {
try {
String serializedMessage = messageMarshaller.serialize(message);
if (snsTestProxy == null) {
PublishRequest request = new PublishRequest();
PublishResult result = client.publish(request.withTopicArn(
topicArn).withMessage(serializedMessage));
log.debug("Published message to topic: "
+ result.getMessageId());
} else {
snsTestProxy.dispatchMessage(serializedMessage);
}
} catch (MessageMarshallerException e) {
log.error(e.getMessage(), e);
throw new MessagingException(e.getMessage(), e.getCause());
}
return message.getPayload();
}
示例10: testArrayOfPojo
import org.springframework.integration.Message; //导入依赖的package包/类
@Test
public void testArrayOfPojo() throws MessageMarshallerException {
TestPojo[] aryIn = new TestPojo[2];
aryIn[0] = new TestPojo();
aryIn[0].setName("John Doe");
aryIn[0].setEmail("[email protected]");
aryIn[1] = new TestPojo();
aryIn[1].setName("Lionel Messi");
aryIn[1].setEmail("[email protected]");
String packet = marshaller.serialize(MessageBuilder.withPayload(aryIn)
.build());
Message<?> otherPacket = marshaller.deserialize(packet);
TestPojo[] aryOut = (TestPojo[]) otherPacket.getPayload();
assertTrue(Arrays.deepEquals(aryIn, aryOut));
}
示例11: incorrectMD5Test
import org.springframework.integration.Message; //导入依赖的package包/类
@Test
public void incorrectMD5Test() throws MessageMarshallerException {
String payload = "Hello, World";
String messageBody = messageMarshaller.serialize(MessageBuilder
.withPayload(payload).build());
com.amazonaws.services.sqs.model.Message sqsMessage = new com.amazonaws.services.sqs.model.Message();
sqsMessage.setBody(messageBody);
sqsMessage.setMD5OfBody(messageBody);
ReceiveMessageResult result = new ReceiveMessageResult();
result.setMessages(Collections.singletonList(sqsMessage));
when(mockSQS.receiveMessage(any(ReceiveMessageRequest.class)))
.thenReturn(result);
Message<?> recvMessage = executor.poll();
assertNull("No message since MD5 checksum failed", recvMessage);
}
示例12: correctMD5Test
import org.springframework.integration.Message; //导入依赖的package包/类
@Test
public void correctMD5Test() throws Exception {
String payload = "Hello, World";
String messageBody = messageMarshaller.serialize(MessageBuilder
.withPayload(payload).build());
com.amazonaws.services.sqs.model.Message sqsMessage = new com.amazonaws.services.sqs.model.Message();
sqsMessage.setBody(messageBody);
sqsMessage.setMD5OfBody(new String(Hex.encodeHex(Md5Utils
.computeMD5Hash(messageBody.getBytes("UTF-8")))));
ReceiveMessageResult result = new ReceiveMessageResult();
result.setMessages(Collections.singletonList(sqsMessage));
when(mockSQS.receiveMessage(any(ReceiveMessageRequest.class)))
.thenReturn(result);
Message<?> recvMessage = executor.poll();
assertNotNull("message is not null", recvMessage);
Message<?> enclosed = messageMarshaller
.deserialize((String) recvMessage.getPayload());
String recvPayload = (String) enclosed.getPayload();
assertEquals("payload must match", payload, recvPayload);
}
示例13: testMessageFlow
import org.springframework.integration.Message; //导入依赖的package包/类
@Test
public void testMessageFlow() throws Exception {
setUp("SqsInboundChannelAdapterParserTests.xml", getClass(),
"sqsInboundChannelAdapter");
@SuppressWarnings("unchecked")
BlockingQueue<String> testQueue = (BlockingQueue<String>) context
.getBean("testQueue");
DirectChannel out = (DirectChannel) context.getBean("out");
out.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message)
throws MessagingException {
assertEquals("Hello, World", message.getPayload());
}
});
testQueue
.add("{\"payload\": \"Hello, World\", \"payloadClazz\": \"java.lang.String\", \"headers\": {}, \"properties\": {}}");
}
示例14: testMessageDrivenFlow
import org.springframework.integration.Message; //导入依赖的package包/类
@Test
public void testMessageDrivenFlow() throws Exception {
setUp("SqsChannelParserTests.xml", getClass(), "sqsChannel");
recvMessage = null;
DirectChannel log = (DirectChannel) context.getBean("log");
log.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message)
throws MessagingException {
recvMessage = (String) message.getPayload();
}
});
String payload = "Hello, World";
MessageChannel channel = (MessageChannel) context.getBean("sqsChannel");
channel.send(MessageBuilder.withPayload(payload).build());
Thread.sleep(1000);
assertEquals(payload, recvMessage);
}
示例15: testPollingFlow
import org.springframework.integration.Message; //导入依赖的package包/类
@Test
public void testPollingFlow() throws Exception {
setUp("SqsPollingChannelParserTests.xml", getClass(), "sqsChannel");
PollableChannel channel = (PollableChannel) context
.getBean("sqsChannel");
String payload = "Hello, World";
channel.send(MessageBuilder.withPayload(payload).build());
Message<?> recv = channel.receive(1000);
assertEquals(payload, recv.getPayload());
@SuppressWarnings("unchecked")
Callable<String> ackCallback = (Callable<String>) recv.getHeaders()
.get(SqsHeaders.ACK_CALLBACK);
assertNotNull(ackCallback);
assertTrue(ackCallback.call().isEmpty());
}