本文整理匯總了Java中org.springframework.messaging.MessageChannel類的典型用法代碼示例。如果您正苦於以下問題:Java MessageChannel類的具體用法?Java MessageChannel怎麽用?Java MessageChannel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MessageChannel類屬於org.springframework.messaging包,在下文中一共展示了MessageChannel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createProducerMessageHandler
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
@Override
protected MessageHandler createProducerMessageHandler(ProducerDestination destination,
ExtendedProducerProperties<KinesisProducerProperties> producerProperties, MessageChannel errorChannel) {
KinesisMessageHandler kinesisMessageHandler = new KinesisMessageHandler(this.amazonKinesis);
kinesisMessageHandler.setSync(producerProperties.getExtension().isSync());
kinesisMessageHandler.setSendTimeout(producerProperties.getExtension().getSendTimeout());
kinesisMessageHandler.setStream(destination.getName());
if (producerProperties.isPartitioned()) {
kinesisMessageHandler
.setPartitionKeyExpressionString("'partitionKey-' + headers." + BinderHeaders.PARTITION_HEADER);
}
kinesisMessageHandler.setFailureChannel(errorChannel);
kinesisMessageHandler.setBeanFactory(getBeanFactory());
return kinesisMessageHandler;
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-aws-kinesis,代碼行數:18,代碼來源:KinesisMessageChannelBinder.java
示例2: test
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
@Test
public void test() throws Exception {
TestSupportBinder binder = (TestSupportBinder) this.binderFactory.getBinder(null);
Message<?> message = MessageBuilder.withPayload("hello").setHeader("route", "foo").build();
this.channels.input().send(message);
message = MessageBuilder.withPayload("hello").setHeader("route", "bar").build();
this.channels.input().send(message);
message = MessageBuilder.withPayload("hello").setHeader("route", "baz").build();
this.channels.input().send(message);
MessageChannel foo = binder.getChannelForName("foo");
assertNotNull(foo);
MessageChannel bar = binder.getChannelForName("bar");
assertNotNull(bar);
MessageChannel baz = binder.getChannelForName("baz");
assertNull(baz);
MessageChannel discards = binder.getChannelForName("discards");
assertNotNull(discards);
assertThat(collector.forChannel(foo), receivesPayloadThat(is("hello")));
assertThat(collector.forChannel(bar), receivesPayloadThat(is("hello")));
assertThat(collector.forChannel(discards), receivesPayloadThat(is("hello")));
}
示例3: preSend
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
@Override
public Message<?> preSend(final Message<?> message, final MessageChannel channel) throws AuthenticationException {
final StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
if (StompCommand.CONNECT == accessor.getCommand()) {
final String username = accessor.getFirstNativeHeader(USERNAME_HEADER);
final String authToken = accessor.getFirstNativeHeader(TOKEN_HEADER);
final Authentication user = webSocketAuthenticatorService.getAuthenticatedOrFail(username, authToken);
accessor.setUser(user);
}
return message;
}
示例4: testGoodConnection
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
@Test
public void testGoodConnection() throws MqttException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
Assert.assertTrue(service.start());
Assert.assertTrue(service.isConnected());
Assert.assertTrue(service.isStarted());
Assert.assertEquals(1, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(0, clientLostConnectionCount.get());
Assert.assertEquals(0, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例5: applyPreSend
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
public Message<?> applyPreSend(Message<?> message, MessageChannel channel) {
Message<?> messageToUse = message;
for (ChannelInterceptor interceptor : interceptors) {
Message<?> resolvedMessage = interceptor.preSend(messageToUse, channel);
if (resolvedMessage == null) {
String name = interceptor.getClass().getSimpleName();
if (logger.isDebugEnabled()) {
logger.debug(name + " returned null from preSend, i.e. precluding the send.");
}
triggerAfterSendCompletion(messageToUse, channel, false, null);
return null;
}
messageToUse = resolvedMessage;
this.sendInterceptorIndex++;
}
return messageToUse;
}
示例6: testAutoConfigureTopicsDisabledSucceedsIfTopicExisting
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testAutoConfigureTopicsDisabledSucceedsIfTopicExisting() throws Throwable {
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
String testTopicName = "existing" + System.currentTimeMillis();
invokeCreateTopic(testTopicName, 5, 1);
configurationProperties.setAutoCreateTopics(false);
Binder binder = getBinder(configurationProperties);
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
DirectChannel input = createBindableChannel("input", createConsumerBindingProperties(consumerProperties));
Binding<MessageChannel> binding = binder.bindConsumer(testTopicName, "test", input, consumerProperties);
binding.unbind();
}
示例7: 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();
}
}
示例8: doRegisterProducer
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
private Binding<MessageChannel> doRegisterProducer(final String name, MessageChannel moduleOutputChannel,
ProducerProperties properties) {
Assert.isInstanceOf(SubscribableChannel.class, moduleOutputChannel);
MessageHandler handler = new SendingHandler(name, properties);
EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) moduleOutputChannel, handler);
consumer.setBeanFactory(this.getBeanFactory());
consumer.setBeanName("outbound." + name);
consumer.afterPropertiesSet();
DefaultBinding<MessageChannel> producerBinding =
new DefaultBinding<>(name, null, moduleOutputChannel, consumer);
String[] requiredGroups = properties.getRequiredGroups();
if (!ObjectUtils.isEmpty(requiredGroups)) {
for (String group : requiredGroups) {
this.redisOperations.boundZSetOps(CONSUMER_GROUPS_KEY_PREFIX + name).incrementScore(group, 1);
}
}
consumer.start();
return producerBinding;
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-redis,代碼行數:20,代碼來源:RedisMessageChannelBinder.java
示例9: bindProducer
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
@Override
public Binding<MessageChannel> bindProducer(String name, MessageChannel moduleOutputChannel,
ExtendedProducerProperties<RabbitProducerProperties> properties) {
this.queues.add(properties.getExtension().getPrefix() + name + ".default");
this.exchanges.add(properties.getExtension().getPrefix() + name);
if (properties.getRequiredGroups() != null) {
for (String group : properties.getRequiredGroups()) {
if (properties.getExtension().isQueueNameGroupOnly()) {
this.queues.add(properties.getExtension().getPrefix() + group);
}
else {
this.queues.add(properties.getExtension().getPrefix() + name + "." + group);
}
}
}
this.prefixes.add(properties.getExtension().getPrefix());
deadLetters(properties.getExtension());
return super.bindProducer(name, moduleOutputChannel, properties);
}
示例10: RpcMessageHandler
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
public RpcMessageHandler(SubscribableChannel clientInboundChannel,
MessageChannel clientOutboundChannel, ProcedureRegistry procedureRegistry,
HandlerMethodService handlerMethodService, Features features) {
this.clientInboundChannel = clientInboundChannel;
this.clientOutboundChannel = clientOutboundChannel;
this.procedureRegistry = procedureRegistry;
this.handlerMethodService = handlerMethodService;
this.features = features;
}
示例11: PubSubMessageHandler
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
public PubSubMessageHandler(SubscribableChannel clientInboundChannel,
SubscribableChannel brokerChannel, MessageChannel clientOutboundChannel,
SubscriptionRegistry subscriptionRegistry,
HandlerMethodService handlerMethodService, Features features,
EventStore eventStore) {
this.clientInboundChannel = clientInboundChannel;
this.brokerChannel = brokerChannel;
this.clientOutboundChannel = clientOutboundChannel;
this.subscriptionRegistry = subscriptionRegistry;
this.handlerMethodService = handlerMethodService;
this.features = features;
this.eventStore = eventStore;
}
示例12: afterSessionEnded
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
@Override
public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus,
MessageChannel outputChannel) {
Long wampSessionId = (Long) session.getAttributes()
.get(WampMessageHeader.WAMP_SESSION_ID.name());
if (wampSessionId != null) {
this.applicationEventPublisher.publishEvent(new WampDisconnectEvent(
wampSessionId, session.getId(), session.getPrincipal()));
this.wampSessionIds.remove(wampSessionId);
session.getAttributes().remove(WampMessageHeader.WAMP_SESSION_ID.name());
}
}
示例13: preSend
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
if (SimpMessageType.MESSAGE.equals(message.getHeaders().get(SIMP_MESSAGE_TYPE))) {
if (Tags.SPAN_KIND_SERVER.equals(spanKind)) {
return preSendServerSpan(message);
} else if (Tags.SPAN_KIND_CLIENT.equals(spanKind)) {
return preSendClientSpan(message);
}
}
return message;
}
示例14: afterMessageHandled
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
@Override
public void afterMessageHandled(Message<?> message, MessageChannel channel,
MessageHandler handler, Exception arg3) {
if ((handler instanceof WebSocketAnnotationMethodMessageHandler ||
handler instanceof SubProtocolWebSocketHandler) &&
SimpMessageType.MESSAGE.equals(message.getHeaders().get(SIMP_MESSAGE_TYPE))) {
tracer.activeSpan().close();
}
}
示例15: beforeHandle
import org.springframework.messaging.MessageChannel; //導入依賴的package包/類
@Override
public Message<?> beforeHandle(Message<?> message, MessageChannel channel,
MessageHandler handler) {
if ((handler instanceof WebSocketAnnotationMethodMessageHandler ||
handler instanceof SubProtocolWebSocketHandler) &&
SimpMessageType.MESSAGE.equals(message.getHeaders().get(SIMP_MESSAGE_TYPE))) {
tracer.makeActive(message.getHeaders().get(OPENTRACING_SPAN, Span.class));
}
return message;
}