本文整理汇总了Java中org.springframework.integration.channel.DirectChannel类的典型用法代码示例。如果您正苦于以下问题:Java DirectChannel类的具体用法?Java DirectChannel怎么用?Java DirectChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirectChannel类属于org.springframework.integration.channel包,在下文中一共展示了DirectChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testProducerPropertiesValidation
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
public void testProducerPropertiesValidation() {
BindingServiceProperties serviceProperties = new BindingServiceProperties();
Map<String, BindingProperties> bindingProperties = new HashMap<>();
BindingProperties props = new BindingProperties();
ProducerProperties producerProperties = new ProducerProperties();
producerProperties.setPartitionCount(0);
props.setDestination("foo");
props.setProducer(producerProperties);
final String outputChannelName = "output";
bindingProperties.put(outputChannelName, props);
serviceProperties.setBindings(bindingProperties);
DefaultBinderFactory binderFactory = createMockBinderFactory();
BindingService service = new BindingService(serviceProperties, binderFactory);
MessageChannel outputChannel = new DirectChannel();
try {
service.bindProducer(outputChannel, outputChannelName);
fail("Producer properties should be validated.");
}
catch (IllegalStateException e) {
assertThat(e).hasMessageContaining("Partition count should be greater than zero.");
}
}
示例2: testUnrecognizedBinderDisallowedIfUsed
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
public void testUnrecognizedBinderDisallowedIfUsed() {
HashMap<String, String> properties = new HashMap<>();
properties.put("spring.cloud.stream.bindings.input.destination", "fooInput");
properties.put("spring.cloud.stream.bindings.input.binder", "mock1");
properties.put("spring.cloud.stream.bindings.output.destination", "fooOutput");
properties.put("spring.cloud.stream.bindings.output.type", "kafka1");
properties.put("spring.cloud.stream.binders.mock1.type", "mock");
properties.put("spring.cloud.stream.binders.kafka1.type", "kafka");
BindingServiceProperties bindingServiceProperties = createBindingServiceProperties(properties);
DefaultBinderFactory binderFactory = new BinderFactoryConfiguration()
.binderFactory(createMockBinderTypeRegistry(), bindingServiceProperties);
BindingService bindingService = new BindingService(bindingServiceProperties,
binderFactory);
bindingService.bindConsumer(new DirectChannel(), "input");
try {
bindingService.bindProducer(new DirectChannel(), "output");
fail("Expected 'Unknown binder configuration'");
}
catch (IllegalArgumentException e) {
assertThat(e).hasMessageContaining("Binder type kafka is not defined");
}
}
示例3: doRegisterConsumer
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
private Binding<MessageChannel> doRegisterConsumer(String bindingName, String group, String channelName, MessageChannel moduleInputChannel,
MessageProducerSupport adapter, final ConsumerProperties properties) {
DirectChannel bridgeToModuleChannel = new DirectChannel();
bridgeToModuleChannel.setBeanFactory(this.getBeanFactory());
bridgeToModuleChannel.setBeanName(channelName + ".bridge");
MessageChannel bridgeInputChannel = addRetryIfNeeded(channelName, bridgeToModuleChannel, properties);
adapter.setOutputChannel(bridgeInputChannel);
adapter.setBeanName("inbound." + channelName);
adapter.afterPropertiesSet();
DefaultBinding<MessageChannel> consumerBinding = new DefaultBinding<MessageChannel>(bindingName, group, moduleInputChannel, adapter) {
@Override
protected void afterUnbind() {
String key = RedisMessageChannelBinder.CONSUMER_GROUPS_KEY_PREFIX + getName();
RedisMessageChannelBinder.this.redisOperations.boundZSetOps(key).incrementScore(getGroup(), -1);
}
};
ReceivingHandler convertingBridge = new ReceivingHandler(properties);
convertingBridge.setOutputChannel(moduleInputChannel);
convertingBridge.setBeanName(channelName + ".bridge.handler");
convertingBridge.afterPropertiesSet();
bridgeToModuleChannel.subscribe(convertingBridge);
this.redisOperations.boundZSetOps(CONSUMER_GROUPS_KEY_PREFIX + bindingName).incrementScore(group, 1);
adapter.start();
return consumerBinding;
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:27,代码来源:RedisMessageChannelBinder.java
示例4: verifyConsumer
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
private void verifyConsumer(AbstractEndpoint endpoint) {
assertThat(endpoint.getClass().getName(), containsString("CompositeRedisQueueMessageDrivenEndpoint"));
assertEquals(2, TestUtils.getPropertyValue(endpoint, "consumers", Collection.class).size());
DirectChannel channel = TestUtils.getPropertyValue(
TestUtils.getPropertyValue(endpoint, "consumers", List.class).get(0),
"outputChannel", DirectChannel.class);
assertThat(
channel.getClass().getName(), containsString(getClassUnderTestName() + "$")); // retry wrapper
assertThat(
TestUtils.getPropertyValue(TestUtils.getPropertyValue(endpoint, "consumers", List.class).get(1),
"outputChannel").getClass().getName(), containsString(getClassUnderTestName() + "$")); // retry wrapper
RetryTemplate retry = TestUtils.getPropertyValue(channel, "val$retryTemplate", RetryTemplate.class);
assertEquals(23, TestUtils.getPropertyValue(retry, "retryPolicy.maxAttempts"));
assertEquals(2000L, TestUtils.getPropertyValue(retry, "backOffPolicy.initialInterval"));
assertEquals(20000L, TestUtils.getPropertyValue(retry, "backOffPolicy.maxInterval"));
assertEquals(5.0, TestUtils.getPropertyValue(retry, "backOffPolicy.multiplier"));
}
示例5: testRetryFail
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
public void testRetryFail() {
RedisTestBinder binder = getBinder();
DirectChannel channel = new DirectChannel();
binder.bindProducer("retry.0", channel, createProducerProperties());
ConsumerProperties consumerProperties = new ConsumerProperties();
consumerProperties.setMaxAttempts(2);
consumerProperties.setBackOffInitialInterval(100);
consumerProperties.setBackOffMultiplier(1.0);
Binding<MessageChannel> consumerBinding = binder.bindConsumer("retry.0", "test", new DirectChannel(), consumerProperties); // no subscriber
channel.send(new GenericMessage<>("foo"));
RedisTemplate<String, Object> template = createTemplate();
Object rightPop = template.boundListOps("ERRORS:retry.0.test").rightPop(5, TimeUnit.SECONDS);
assertNotNull(rightPop);
assertThat(new String((byte[]) rightPop), containsString("foo"));
consumerBinding.unbind();
}
示例6: setUp
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Before
public void setUp() {
messages.clear();
this.connectionFactory = redisAvailableRule.getResource();
DirectChannel outputChannel = new DirectChannel();
outputChannel.setBeanFactory(BinderTestUtils.MOCK_BF);
outputChannel.subscribe(new TestMessageHandler());
this.currentQueueName = QUEUE_NAME + ":" + System.nanoTime();
adapter = new RedisQueueMessageDrivenEndpoint(currentQueueName, connectionFactory);
adapter.setBeanFactory(BinderTestUtils.MOCK_BF);
adapter.setOutputChannel(outputChannel);
String multiplier = System.getenv("REDIS_TIMEOUT_MULTIPLIER");
if (multiplier != null) {
timeoutMultiplier = Double.parseDouble(multiplier);
}
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:20,代码来源:RedisQueueInboundChannelAdapterTests.java
示例7: testSendAndReceive
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
@Override
public void testSendAndReceive() throws Exception {
RedisTestBinder binder = getBinder();
DirectChannel moduleOutputChannel = new DirectChannel();
QueueChannel moduleInputChannel = new QueueChannel();
ProducerProperties producerProperties = createProducerProperties();
producerProperties.setHeaderMode(HeaderMode.raw);
Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel, producerProperties);
ConsumerProperties consumerProperties = createConsumerProperties();
consumerProperties.setHeaderMode(HeaderMode.raw);
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "test", moduleInputChannel, consumerProperties);
Message<?> message = MessageBuilder.withPayload("foo".getBytes()).build();
// Let the consumer actually bind to the producer before sending a msg
binderBindUnbindLatency();
moduleOutputChannel.send(message);
Message<?> inbound = receive(moduleInputChannel);
assertNotNull(inbound);
assertEquals("foo", new String((byte[])inbound.getPayload()));
producerBinding.unbind();
consumerBinding.unbind();
}
示例8: testAutoConfigureTopicsDisabledSucceedsIfTopicExisting
import org.springframework.integration.channel.DirectChannel; //导入依赖的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();
}
示例9: testPartitionCountIncreasedIfAutoAddPartitionsSet
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testPartitionCountIncreasedIfAutoAddPartitionsSet() throws Throwable {
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
String testTopicName = "existing" + System.currentTimeMillis();
configurationProperties.setMinPartitionCount(6);
configurationProperties.setAutoAddPartitions(true);
Binder binder = getBinder(configurationProperties);
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
DirectChannel input = createBindableChannel("input", createConsumerBindingProperties(consumerProperties));
Binding<?> binding = binder.bindConsumer(testTopicName, "test", input, consumerProperties);
binding.unbind();
assertThat(invokePartitionSize(testTopicName)).isEqualTo(6);
}
示例10: testAutoAddPartitionsDisabledSucceedsIfTopicUnderPartitionedAndAutoRebalanceEnabled
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testAutoAddPartitionsDisabledSucceedsIfTopicUnderPartitionedAndAutoRebalanceEnabled() throws Throwable {
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
String testTopicName = "existing" + System.currentTimeMillis();
invokeCreateTopic(testTopicName, 1, 1);
configurationProperties.setAutoAddPartitions(false);
Binder binder = getBinder(configurationProperties);
GenericApplicationContext context = new GenericApplicationContext();
context.refresh();
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
DirectChannel input = createBindableChannel("input", createConsumerBindingProperties(consumerProperties));
// this consumer must consume from partition 2
consumerProperties.setInstanceCount(3);
consumerProperties.setInstanceIndex(2);
Binding binding = binder.bindConsumer(testTopicName, "test", input, consumerProperties);
binding.unbind();
assertThat(invokePartitionSize(testTopicName)).isEqualTo(1);
}
示例11: testAutoAddPartitionsDisabledFailsIfTopicUnderPartitionedAndAutoRebalanceDisabled
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testAutoAddPartitionsDisabledFailsIfTopicUnderPartitionedAndAutoRebalanceDisabled() throws Throwable {
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
String testTopicName = "existing" + System.currentTimeMillis();
invokeCreateTopic(testTopicName, 1, 1);
configurationProperties.setAutoAddPartitions(false);
Binder binder = getBinder(configurationProperties);
GenericApplicationContext context = new GenericApplicationContext();
context.refresh();
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
DirectChannel output = createBindableChannel("output", createConsumerBindingProperties(consumerProperties));
// this consumer must consume from partition 2
consumerProperties.setInstanceCount(3);
consumerProperties.setInstanceIndex(2);
consumerProperties.getExtension().setAutoRebalanceEnabled(false);
expectedProvisioningException.expect(ProvisioningException.class);
expectedProvisioningException
.expectMessage("The number of expected partitions was: 3, but 1 has been found instead");
Binding binding = binder.bindConsumer(testTopicName, "test", output, consumerProperties);
if (binding != null) {
binding.unbind();
}
}
示例12: testPartitionCountNotReduced
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testPartitionCountNotReduced() throws Throwable {
String testTopicName = "existing" + System.currentTimeMillis();
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
invokeCreateTopic(testTopicName, 6, 1);
configurationProperties.setAutoAddPartitions(true);
Binder binder = getBinder(configurationProperties);
GenericApplicationContext context = new GenericApplicationContext();
context.refresh();
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
DirectChannel input = createBindableChannel("input", createConsumerBindingProperties(consumerProperties));
Binding<?> binding = binder.bindConsumer(testTopicName, "test", input, consumerProperties);
binding.unbind();
assertThat(partitionSize(testTopicName)).isEqualTo(6);
}
示例13: testConsumerDefaultDeserializer
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testConsumerDefaultDeserializer() throws Throwable {
Binding<?> binding = null;
try {
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 = binder.bindConsumer(testTopicName, "test", input, consumerProperties);
DirectFieldAccessor consumerAccessor = new DirectFieldAccessor(getKafkaConsumer(binding));
assertTrue(consumerAccessor.getPropertyValue("keyDeserializer") instanceof ByteArrayDeserializer);
assertTrue(consumerAccessor.getPropertyValue("valueDeserializer") instanceof ByteArrayDeserializer);
}
finally {
if (binding != null) {
binding.unbind();
}
}
}
示例14: shouldPublishMessageWithBytePayload
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
public void shouldPublishMessageWithBytePayload() {
// given
DirectChannel output = new DirectChannel();
ArgumentCaptor<URI> uriCaptor = ArgumentCaptor.forClass(URI.class);
ArgumentCaptor<HermesMessage> messageCaptor = ArgumentCaptor.forClass(HermesMessage.class);
// when
Binding<MessageChannel> binding = binder.bindProducer(
OUTPUT_NAME, output, new ExtendedProducerProperties<>(new HermesProducerProperties()));
// then
output.send(new GenericMessage<>(MESSAGE, json()));
verify(hermesSender).send(uriCaptor.capture(), messageCaptor.capture());
assertEquals("http://localhost:8080/topics/topic", uriCaptor.getValue().toString());
assertArrayEquals(MESSAGE.getBytes(), messageCaptor.getValue().getBody());
binding.unbind();
}
示例15: shouldPublishMessageWithError
import org.springframework.integration.channel.DirectChannel; //导入依赖的package包/类
@Test
public void shouldPublishMessageWithError() {
// given
reset(hermesSender);
final HermesResponse response = HermesResponseBuilder.hermesResponse()
.withHttpStatus(500)
.build();
when(hermesSender.send(any(URI.class), any(HermesMessage.class)))
.thenReturn(CompletableFuture.completedFuture(response));
DirectChannel output = new DirectChannel();
// when
Binding<MessageChannel> binding = binder.bindProducer(
OUTPUT_NAME, output, new ExtendedProducerProperties<>(new HermesProducerProperties()));
// then
output.send(new GenericMessage<>(MESSAGE, json()));
verify(hermesSender, times(4)).send(any(URI.class), any(HermesMessage.class));
binding.unbind();
}