• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Message类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.integration.Message的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Message类属于org.springframework.integration包,在下文中一共展示了Message类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
           }
       }*/
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:27,代码来源:MessageHandler.java


示例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;
	}
}
 
开发者ID:mattiamascia,项目名称:atask,代码行数:18,代码来源:AsyncChannel.java


示例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);
			}
		}
	}
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:22,代码来源:SqsSubscribableChannelAdapter.java


示例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;
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:25,代码来源:SqsSubscribableChannelAdapter.java


示例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);
					}
				}

			});
		}
	}
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:23,代码来源:SubscribableSqsChannel.java


示例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;
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:27,代码来源:SubscribableSqsChannel.java


示例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();
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:24,代码来源:SqsExecutor.java


示例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...");
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:21,代码来源:SnsInboundChannelAdapter.java


示例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();
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:27,代码来源:SnsExecutor.java


示例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));

}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:21,代码来源:JsonMessageMarshallerTest.java


示例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);
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:19,代码来源:SqsExecutorTest.java


示例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);
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:25,代码来源:SqsExecutorTest.java


示例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\": {}}");

}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:24,代码来源:SqsInboundChannelAdapterParserTests.java


示例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);
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:23,代码来源:SqsChannelParserTests.java


示例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());
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:20,代码来源:SqsChannelParserTests.java


示例16: testMessageFlow

import org.springframework.integration.Message; //导入依赖的package包/类
@Test
public void testMessageFlow() throws Exception {

	setUp("SnsChannelParserTests.xml", getClass(), "snsChannel");

	recvPayload = null;
	PublishSubscribeSnsChannel snsChannel = (PublishSubscribeSnsChannel) context
			.getBean("snsChannel");
	snsChannel.subscribe(new MessageHandler() {

		@Override
		public void handleMessage(Message<?> message)
				throws MessagingException {
			recvPayload = message.getPayload();
		}
	});

	String payload = "Hello, World";
	snsChannel.send(MessageBuilder.withPayload(payload).build());
	Thread.sleep(1000);

	assertNotNull(recvPayload);
	assertEquals(payload, recvPayload);
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:25,代码来源:SnsChannelParserTests.java


示例17: process

import org.springframework.integration.Message; //导入依赖的package包/类
public PersonTax process(Person item) {
    	
        Message<?> inputMessage = MessageBuilder.withPayload(item).build();
//
        Message<?> outputMessage = this.messagingGateway.sendAndReceive(this.integrationInputChannel, inputMessage);

//        return outputMessage;
        
        PersonTax personTax = (PersonTax) outputMessage.getPayload();
        
        if (item.getDependents() > 0) {
			personTax.setFree(true);
		}else{
			personTax.setFree(false);
		}
        
        personTax.setDate(new Date(System.currentTimeMillis()));
		personTax.setTax(item.getSalary()*1.05);
        
    	return personTax;
    }
 
开发者ID:osnircunha,项目名称:SpringFrameworkSamples,代码行数:22,代码来源:MyItemProcessor.java


示例18: prepareMessage

import org.springframework.integration.Message; //导入依赖的package包/类
/**
 * Prepare a message for outgoing email
 *
 * @param message
 * @return
 */
public Message<Map> prepareMessage(Message<?> message) {
	Map<String, Object> model = new HashMap<String, Object>();
	Map<String, Object> headers = new HashMap<String, Object>();
	headers.putAll(message.getHeaders());
	Object payload = message.getPayload();
	if (payload instanceof Comment) {
		model.put("comment", payload);
		// Decide which template
		Base about = ((Comment) payload).getAboutData();
		String templateName = null;
		if(((Comment) payload).getInResponseTo() != null) {
			templateName = "reply";
		} else if (about instanceof BaseData) {
			templateName = "comment";
		} else if (about instanceof Resource) {
			templateName = "resource";
		}
		if (templateName != null) {
			headers.put(HEADER_TEMPLATE_NAME, templates.get(templateName));
		} else {
			headers.put(HEADER_TEMPLATE_NAME,
					templates.get(defaultTemplateName));
		}
	}
	return new GenericMessage<Map>(model, headers);

}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:34,代码来源:EmailServiceHelper.java


示例19: splitMessage

import org.springframework.integration.Message; //导入依赖的package包/类
@Override
protected List<Message<Object>> splitMessage(Message<?> message) {
	List<Message<Object>> split = new ArrayList<Message<Object>>();
	Message<Object> m;
	for(Object o : (Iterable) message.getHeaders().get(requestKey)) {
		Map<String, Object> newHeaders = new HashMap<String, Object>();
		newHeaders.putAll(message.getHeaders());
		if(responseKey != null) {
			newHeaders.put(responseKey, o);
		}
		m = new GenericMessage<Object>(message.getPayload(), newHeaders);
		split.add(m);
	}
	return split;
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:16,代码来源:HeaderCollectionSplitter.java


示例20: process

import org.springframework.integration.Message; //导入依赖的package包/类
/**
 * Processes the thread id
 *
 * @param id the id
 * @return the async context
 */
public AsyncContext process(String id) {
	IdMessageSelector selector = (IdMessageSelector) ContextLoader
			.getCurrentWebApplicationContext().getBean(
					IdMessageSelector.BEAN);
	selector.setThreadId(id);
	List<Message<?>> listMessages = channel.purge(selector);
	if (listMessages.size() > 0) {
		Message<?> reportMessage = listMessages.get(0); // 1 a 1;
		if (reportMessage != null) {
			return (AsyncContext) reportMessage.getPayload();
		}
	}
	return null;
}
 
开发者ID:mattiamascia,项目名称:atask,代码行数:21,代码来源:DownloadCtr.java



注:本文中的org.springframework.integration.Message类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ReactInstanceDevCommandsHandler类代码示例发布时间:2022-05-22
下一篇:
Java JPFLogger类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap