本文整理汇总了Java中org.springframework.messaging.SubscribableChannel类的典型用法代码示例。如果您正苦于以下问题:Java SubscribableChannel类的具体用法?Java SubscribableChannel怎么用?Java SubscribableChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SubscribableChannel类属于org.springframework.messaging包,在下文中一共展示了SubscribableChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
@Override
public void run(ApplicationArguments args) throws Exception {
logger.info("Consumer running with binder {}", binder);
SubscribableChannel consumerChannel = new ExecutorSubscribableChannel();
consumerChannel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
messagePayload = (String) message.getPayload();
logger.info("Received message: {}", messagePayload);
}
});
String group = null;
if (args.containsOption("group")) {
group = args.getOptionValues("group").get(0);
}
binder.bindConsumer(ConsulBinderTests.BINDING_NAME, group, consumerChannel,
new ConsumerProperties());
isBound = true;
}
示例2: SimpAnnotationMethodMessageHandler
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
/**
* Create an instance of SimpAnnotationMethodMessageHandler with the given
* message channels and broker messaging template.
* @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
* @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients)
* @param brokerTemplate a messaging template to send application messages to the broker
*/
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) {
Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null");
Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null");
Assert.notNull(brokerTemplate, "brokerTemplate must not be null");
this.clientInboundChannel = clientInboundChannel;
this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel);
this.brokerTemplate = brokerTemplate;
Collection<MessageConverter> converters = new ArrayList<MessageConverter>();
converters.add(new StringMessageConverter());
converters.add(new ByteArrayMessageConverter());
this.messageConverter = new CompositeMessageConverter(converters);
}
示例3: doRegisterProducer
import org.springframework.messaging.SubscribableChannel; //导入依赖的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
示例4: outputAsync
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
@Bean
public MessageChannel outputAsync(
@Qualifier("jmsConnectionFactory") ConnectionFactory connectionFactory,
DestinationResolver destinationResolver) {
DynamicJmsTemplate jmsTemplate = new DynamicJmsTemplate();
jmsTemplate.setConnectionFactory(connectionFactory);
jmsTemplate.setDestinationResolver(destinationResolver);
// TODO server should be detecting conversion type
jmsTemplate.setMessageConverter(new XmlEncoderDecoderConverter());
JmsSendingMessageHandler handler = new JmsSendingMessageHandler(jmsTemplate);
handler.setDestinationName("server.queue");
SubscribableChannel ch = new FixedSubscriberChannel(handler);
return ch;
}
示例5: destroyErrorInfrastructure
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
private void destroyErrorInfrastructure(ProducerDestination destination) {
String errorChannelName = errorsBaseName(destination);
String errorBridgeHandlerName = getErrorBridgeName(destination);
MessageHandler bridgeHandler = null;
if (getApplicationContext().containsBean(errorBridgeHandlerName)) {
bridgeHandler = getApplicationContext().getBean(errorBridgeHandlerName, MessageHandler.class);
}
if (getApplicationContext().containsBean(errorChannelName)) {
SubscribableChannel channel = getApplicationContext().getBean(errorChannelName, SubscribableChannel.class);
if (bridgeHandler != null) {
channel.unsubscribe(bridgeHandler);
((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
.destroySingleton(errorBridgeHandlerName);
}
((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
.destroySingleton(errorChannelName);
}
}
示例6: createConsumerEndpoint
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
@Override
protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ConsumerProperties properties)
throws Exception {
ErrorMessageStrategy errorMessageStrategy = new DefaultErrorMessageStrategy();
SubscribableChannel siBinderInputChannel = ((SpringIntegrationConsumerDestination)destination).getChannel();
IntegrationMessageListeningContainer messageListenerContainer = new IntegrationMessageListeningContainer();
IntegrationBinderInboundChannelAdapter adapter = new IntegrationBinderInboundChannelAdapter(messageListenerContainer);
String groupName = StringUtils.hasText(group) ? group : "anonymous";
ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination, groupName, properties);
if (properties.getMaxAttempts() > 1) {
adapter.setRetryTemplate(buildRetryTemplate(properties));
adapter.setRecoveryCallback(errorInfrastructure.getRecoverer());
}
else {
adapter.setErrorMessageStrategy(errorMessageStrategy);
adapter.setErrorChannel(errorInfrastructure.getErrorChannel());
}
siBinderInputChannel.subscribe(messageListenerContainer);
return adapter;
}
示例7: testMethodWithMultipleInputParameters
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
@Test
public void testMethodWithMultipleInputParameters() throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(TestMethodWithMultipleInputParameters.class,
"--server.port=0",
"--spring.jmx.enabled=false");
Processor processor = context.getBean(Processor.class);
StreamListenerTestUtils.FooInboundChannel1 inboundChannel2 = context
.getBean(StreamListenerTestUtils.FooInboundChannel1.class);
final CountDownLatch latch = new CountDownLatch(2);
((SubscribableChannel) processor.output()).subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
Assert.isTrue(message.getPayload().equals("footesting") || message.getPayload().equals("BARTESTING"), "Assert failed");
latch.countDown();
}
});
processor.input().send(MessageBuilder.withPayload("{\"foo\":\"fooTESTing\"}")
.setHeader("contentType", "application/json").build());
inboundChannel2.input().send(MessageBuilder.withPayload("{\"bar\":\"bartestING\"}")
.setHeader("contentType", "application/json").build());
assertThat(latch.await(1, TimeUnit.SECONDS));
context.close();
}
示例8: receive
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
@StreamListener
public void receive(@Input(Processor.INPUT) SubscribableChannel input,
@Output(Processor.OUTPUT) final MessageChannel output1,
@Output(StreamListenerTestUtils.FooOutboundChannel1.OUTPUT) final MessageChannel output2) {
input.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
if (message.getHeaders().get("output").equals("output1")) {
output1.send(org.springframework.messaging.support.MessageBuilder
.withPayload(message.getPayload().toString().toUpperCase()).build());
}
else if (message.getHeaders().get("output").equals("output2")) {
output2.send(org.springframework.messaging.support.MessageBuilder
.withPayload(message.getPayload().toString().toLowerCase()).build());
}
}
});
}
示例9: SimpleBrokerMessageHandler
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
public SimpleBrokerMessageHandler(SubscribableChannel inboundChannel,
MessageChannel outboundChannel, SubscribableChannel brokerChannel,
SubscriptionRegistry subscriptionRegistry,
WampMessageSelector wampMessageSelector) {
Assert.notNull(inboundChannel, "'inboundChannel' must not be null");
Assert.notNull(outboundChannel, "'outboundChannel' must not be null");
Assert.notNull(brokerChannel, "'brokerChannel' must not be null");
Assert.notNull(subscriptionRegistry, "'subscriptionRegistry' must not be null");
Assert.notNull(wampMessageSelector, "'wampMessageSelector' must not be null");
this.clientInboundChannel = inboundChannel;
this.clientOutboundChannel = outboundChannel;
this.brokerChannel = brokerChannel;
this.subscriptionRegistry = subscriptionRegistry;
this.wampMessageSelector = wampMessageSelector;
}
示例10: test
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
@Test
public void test() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
Properties properties = new Properties();
properties.put("prefix","foo");
properties.put("suffix","bar");
context.getEnvironment().getPropertySources().addLast(new PropertiesPropertySource("options", properties));
context.register(TestConfiguration.class);
context.refresh();
MessageChannel input = context.getBean("input", MessageChannel.class);
SubscribableChannel output = context.getBean("output", SubscribableChannel.class);
final AtomicBoolean handled = new AtomicBoolean();
output.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
handled.set(true);
assertEquals("foohellobar", message.getPayload());
}
});
input.send(new GenericMessage<String>("hello"));
assertTrue(handled.get());
}
示例11: RpcMessageHandler
import org.springframework.messaging.SubscribableChannel; //导入依赖的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;
}
示例12: PubSubMessageHandler
import org.springframework.messaging.SubscribableChannel; //导入依赖的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;
}
示例13: clientInboundChannel
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
@Bean
public SubscribableChannel clientInboundChannel() {
ExecutorSubscribableChannel executorSubscribableChannel = new ExecutorSubscribableChannel(
clientInboundChannelExecutor());
configureClientInboundChannel(executorSubscribableChannel);
for (WampConfigurer wc : this.configurers) {
wc.configureClientInboundChannel(executorSubscribableChannel);
}
return executorSubscribableChannel;
}
示例14: springMessagingEventBus
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public EventBus springMessagingEventBus(
final SubscribableChannel channel) {
final SpringMessagingEventBus eventBus
= new SpringMessagingEventBus();
eventBus.setChannel(channel);
return eventBus;
}
示例15: UserDestinationMessageHandler
import org.springframework.messaging.SubscribableChannel; //导入依赖的package包/类
/**
* Create an instance with the given client and broker channels subscribing
* to handle messages from each and then sending any resolved messages to the
* broker channel.
* @param clientInboundChannel messages received from clients.
* @param brokerChannel messages sent to the broker.
* @param resolver the resolver for "user" destinations.
*/
public UserDestinationMessageHandler(SubscribableChannel clientInboundChannel,
SubscribableChannel brokerChannel, UserDestinationResolver resolver) {
Assert.notNull(clientInboundChannel, "'clientInChannel' must not be null");
Assert.notNull(brokerChannel, "'brokerChannel' must not be null");
Assert.notNull(resolver, "resolver must not be null");
this.clientInboundChannel = clientInboundChannel;
this.brokerChannel = brokerChannel;
this.messagingTemplate = new SimpMessagingTemplate(brokerChannel);
this.destinationResolver = resolver;
}