本文整理汇总了Java中org.springframework.messaging.MessageChannel.send方法的典型用法代码示例。如果您正苦于以下问题:Java MessageChannel.send方法的具体用法?Java MessageChannel.send怎么用?Java MessageChannel.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.messaging.MessageChannel
的用法示例。
在下文中一共展示了MessageChannel.send方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doSend
import org.springframework.messaging.MessageChannel; //导入方法依赖的package包/类
@Override
protected final void doSend(MessageChannel channel, Message<?> message) {
Assert.notNull(channel, "'channel' is required");
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
if (accessor != null && accessor.isMutable()) {
accessor.setImmutable();
}
long timeout = this.sendTimeout;
boolean sent = (timeout >= 0 ? channel.send(message, timeout) : channel.send(message));
if (!sent) {
throw new MessageDeliveryException(message,
"failed to send message to channel '" + channel + "' within timeout: " + timeout);
}
}
示例2: afterSessionEnded
import org.springframework.messaging.MessageChannel; //导入方法依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) {
this.decoders.remove(session.getId());
Principal principal = session.getPrincipal();
if (principal != null && this.userSessionRegistry != null) {
String userName = getSessionRegistryUserName(principal);
this.userSessionRegistry.unregisterSessionId(userName, session.getId());
}
Message<byte[]> message = createDisconnectMessage(session);
SimpAttributes simpAttributes = SimpAttributes.fromMessage(message);
try {
SimpAttributesContextHolder.setAttributes(simpAttributes);
if (this.eventPublisher != null) {
Principal user = session.getPrincipal();
publishEvent(new SessionDisconnectEvent(this, message, session.getId(), closeStatus, user));
}
outputChannel.send(message);
}
finally {
SimpAttributesContextHolder.resetAttributes();
simpAttributes.sessionCompleted();
}
}
示例3: logs
import org.springframework.messaging.MessageChannel; //导入方法依赖的package包/类
@RequestMapping(value = "/logs", method = RequestMethod.POST)
@ResponseBody
public String logs(@RequestBody String body) throws IOException {
// "application/logplex-1" does not conform to RFC5424.
// It leaves out STRUCTURED-DATA but does not replace it with
// a NILVALUE. To workaround this, we inject empty STRUCTURED-DATA.
String[] parts = body.split("router - ");
String log = parts[0] + "router - [] " + (parts.length > 1 ? parts[1] : "");
RFC6587SyslogDeserializer parser = new RFC6587SyslogDeserializer();
InputStream is = new ByteArrayInputStream(log.getBytes());
Map<String, ?> messages = parser.deserialize(is);
ObjectMapper mapper = new ObjectMapper();
MessageChannel toKafka = context.getBean("toKafka", MessageChannel.class);
String json = mapper.writeValueAsString(messages);
toKafka.send(new GenericMessage<>(json));
return "ok";
}
示例4: testIntegration
import org.springframework.messaging.MessageChannel; //导入方法依赖的package包/类
@Test
public void testIntegration() throws Exception {
MessageChannel producingChannel =
applicationContext.getBean("producingChannel", MessageChannel.class);
Map<String, Object> headers =
Collections.singletonMap(KafkaHeaders.TOPIC, SPRING_INTEGRATION_KAFKA_TOPIC);
LOGGER.info("sending 10 messages");
for (int i = 0; i < 10; i++) {
GenericMessage<String> message =
new GenericMessage<>("Hello Spring Integration Kafka " + i + "!", headers);
producingChannel.send(message);
LOGGER.info("sent message='{}'", message);
}
countDownLatchHandler.getLatch().await(10000, TimeUnit.MILLISECONDS);
assertThat(countDownLatchHandler.getLatch().getCount()).isEqualTo(0);
}
示例5: append
import org.springframework.messaging.MessageChannel; //导入方法依赖的package包/类
private void append(String name, Message<?> message) {
String key = (String) message.getHeaders().get(ROUTE_KEY);
if (message.getHeaders().getReplyChannel() instanceof MessageChannel) {
MessageChannel replyChannel = (MessageChannel) message.getHeaders()
.getReplyChannel();
replyChannel.send(message);
return;
}
Route route = new Route(key, name);
String path = route.getPath();
if (!queues.containsKey(path)) {
Bridge<Message<?>> flux = new Bridge<>();
queues.putIfAbsent(path, flux);
}
queues.get(path).send(message);
if (emitters.containsKey(path)) {
Set<SseEmitter> list = new HashSet<>(emitters.get(path));
for (SseEmitter emitter : list) {
try {
emitter.send(message.getPayload());
}
catch (IOException e) {
emitters.get(path).remove(emitter);
}
}
}
}
示例6: send
import org.springframework.messaging.MessageChannel; //导入方法依赖的package包/类
public boolean send(Message<?> message) throws Exception {
boolean result = false;
ExchangePattern pattern;
if (isExpectReply()) {
pattern = ExchangePattern.InOut;
} else {
pattern = ExchangePattern.InOnly;
}
Exchange inExchange = new DefaultExchange(getCamelContext(), pattern);
SpringIntegrationBinding.storeToCamelMessage(message, inExchange.getIn());
Exchange outExchange = getCamelTemplate().send(getCamelEndpointUri(), inExchange);
org.apache.camel.Message camelMsg = outExchange.hasOut() ? outExchange.getOut() : outExchange.getIn();
if (camelMsg.isFault()) {
result = true;
}
Message<?> response;
if (isExpectReply()) {
//Check the message header for the return address
response = SpringIntegrationBinding.storeToSpringIntegrationMessage(outExchange.getOut());
if (replyChannel == null) {
MessageChannel messageReplyChannel = (MessageChannel) message.getHeaders().get(MessageHeaders.REPLY_CHANNEL);
if (messageReplyChannel != null) {
result = messageReplyChannel.send(response);
} else {
throw new MessageDeliveryException(response, "Cannot resolve ReplyChannel from message: " + message);
}
} else {
result = replyChannel.send(response);
}
}
return result;
}
示例7: testSendingOneWayMessage
import org.springframework.messaging.MessageChannel; //导入方法依赖的package包/类
@Test
public void testSendingOneWayMessage() throws Exception {
MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);
MessageChannel outputChannel = getMandatoryBean(MessageChannel.class, "outputChannel");
outputChannel.send(new GenericMessage<Object>(MESSAGE_BODY));
assertMockEndpointsSatisfied();
}
示例8: testSendingOneWayMessage
import org.springframework.messaging.MessageChannel; //导入方法依赖的package包/类
@Test
public void testSendingOneWayMessage() throws Exception {
MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);
MessageChannel outputChannel = getMandatoryBean(MessageChannel.class, "channelA");
outputChannel.send(new GenericMessage<Object>(MESSAGE_BODY));
assertMockEndpointsSatisfied();
}
示例9: main
import org.springframework.messaging.MessageChannel; //导入方法依赖的package包/类
public static void main (String[] args){
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/HelloWorldDemo.xml",App.class);
MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class);
inputChannel.send(new GenericMessage<String>("World Mundo da Integração"));
logger.info("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload());
context.close();
}