当前位置: 首页>>代码示例>>Java>>正文


Java SubscribableChannel类代码示例

本文整理汇总了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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-consul,代码行数:22,代码来源:TestConsumer.java

示例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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:SimpAnnotationMethodMessageHandler.java

示例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;
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:17,代码来源:ClientApplication.java

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

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

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

示例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());
			}
		}
	});
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:19,代码来源:StreamListenerHandlerMethodTests.java

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

示例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());
}
 
开发者ID:spring-projects,项目名称:spring-xd-samples,代码行数:25,代码来源:ModuleConfigurationTest.java

示例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;
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:10,代码来源:RpcMessageHandler.java

示例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;
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:14,代码来源:PubSubMessageHandler.java

示例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;
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:13,代码来源:WampConfiguration.java

示例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;
}
 
开发者ID:binkley,项目名称:axon-spring-boot-starter,代码行数:10,代码来源:AxonSpringMessagingAutoConfiguration.java

示例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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:UserDestinationMessageHandler.java


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