本文整理汇总了Java中org.springframework.cloud.stream.binder.ConsumerProperties.setConcurrency方法的典型用法代码示例。如果您正苦于以下问题:Java ConsumerProperties.setConcurrency方法的具体用法?Java ConsumerProperties.setConcurrency怎么用?Java ConsumerProperties.setConcurrency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.cloud.stream.binder.ConsumerProperties
的用法示例。
在下文中一共展示了ConsumerProperties.setConcurrency方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConsumerPropertiesValidation
import org.springframework.cloud.stream.binder.ConsumerProperties; //导入方法依赖的package包/类
@Test
public void testConsumerPropertiesValidation() {
BindingServiceProperties serviceProperties = new BindingServiceProperties();
Map<String, BindingProperties> bindingProperties = new HashMap<>();
BindingProperties props = new BindingProperties();
ConsumerProperties consumerProperties = new ConsumerProperties();
consumerProperties.setConcurrency(0);
props.setDestination("foo");
props.setConsumer(consumerProperties);
final String inputChannelName = "input";
bindingProperties.put(inputChannelName, props);
serviceProperties.setBindings(bindingProperties);
DefaultBinderFactory binderFactory = createMockBinderFactory();
BindingService service = new BindingService(serviceProperties,
binderFactory);
MessageChannel inputChannel = new DirectChannel();
try {
service.bindConsumer(inputChannel, inputChannelName);
fail("Consumer properties should be validated.");
}
catch (IllegalStateException e) {
assertThat(e).hasMessageContaining("Concurrency should be greater than zero.");
}
}
示例2: testConsumerProperties
import org.springframework.cloud.stream.binder.ConsumerProperties; //导入方法依赖的package包/类
@Test
public void testConsumerProperties() throws Exception {
RedisTestBinder binder = getBinder();
ConsumerProperties properties1 = new ConsumerProperties();
properties1.setMaxAttempts(1);
Binding<MessageChannel> binding = binder.bindConsumer("props.0", "test", new DirectChannel(), properties1);
AbstractEndpoint endpoint = extractEndpoint(binding);
assertThat(endpoint, instanceOf(RedisQueueMessageDrivenEndpoint.class));
assertSame(DirectChannel.class, TestUtils.getPropertyValue(endpoint, "outputChannel").getClass());
binding.unbind();
assertFalse(endpoint.isRunning());
ConsumerProperties properties2 = new ConsumerProperties();
properties2.setBackOffInitialInterval(2000);
properties2.setBackOffMaxInterval(20000);
properties2.setBackOffMultiplier(5.0);
properties2.setConcurrency(2);
properties2.setMaxAttempts(23);
properties2.setInstanceIndex(0);
binding = binder.bindConsumer("props.0", "test", new DirectChannel(), properties2);
endpoint = extractEndpoint(binding);
verifyConsumer(endpoint);
binding.unbind();
assertFalse(endpoint.isRunning());
}
示例3: testPartitionedModuleJava
import org.springframework.cloud.stream.binder.ConsumerProperties; //导入方法依赖的package包/类
@Test
@Override
public void testPartitionedModuleJava() throws Exception {
RedisTestBinder binder = getBinder();
ProducerProperties properties = createProducerProperties();
properties.setHeaderMode(HeaderMode.raw);
properties.setPartitionKeyExtractorClass(RawRedisPartitionTestSupport.class);
properties.setPartitionSelectorClass(RawRedisPartitionTestSupport.class);
properties.setPartitionCount(3);
DirectChannel output = new DirectChannel();
output.setBeanName("test.output");
Binding<MessageChannel> outputBinding = binder.bindProducer("partJ.0", output, properties);
ConsumerProperties consumerProperties = createConsumerProperties();
consumerProperties.setHeaderMode(HeaderMode.raw);
consumerProperties.setConcurrency(2);
consumerProperties.setInstanceCount(3);
consumerProperties.setInstanceIndex(0);
consumerProperties.setPartitioned(true);
QueueChannel input0 = new QueueChannel();
input0.setBeanName("test.input0J");
Binding<MessageChannel> input0Binding = binder.bindConsumer("partJ.0", "test", input0, consumerProperties);
consumerProperties.setInstanceIndex(1);
QueueChannel input1 = new QueueChannel();
input1.setBeanName("test.input1J");
Binding<MessageChannel> input1Binding = binder.bindConsumer("partJ.0", "test", input1, consumerProperties);
consumerProperties.setInstanceIndex(2);
QueueChannel input2 = new QueueChannel();
input2.setBeanName("test.input2J");
Binding<MessageChannel> input2Binding = binder.bindConsumer("partJ.0", "test", input2, consumerProperties);
output.send(new GenericMessage<>(new byte[]{(byte)0}));
output.send(new GenericMessage<>(new byte[]{(byte)1}));
output.send(new GenericMessage<>(new byte[]{(byte)2}));
Message<?> receive0 = receive(input0);
assertNotNull(receive0);
Message<?> receive1 = receive(input1);
assertNotNull(receive1);
Message<?> receive2 = receive(input2);
assertNotNull(receive2);
assertThat(Arrays.asList(
((byte[]) receive0.getPayload())[0],
((byte[]) receive1.getPayload())[0],
((byte[]) receive2.getPayload())[0]),
containsInAnyOrder((byte)0, (byte)1, (byte)2));
input0Binding.unbind();
input1Binding.unbind();
input2Binding.unbind();
outputBinding.unbind();
}
示例4: testPartitionedModuleSpEL
import org.springframework.cloud.stream.binder.ConsumerProperties; //导入方法依赖的package包/类
@Test
@Override
public void testPartitionedModuleSpEL() throws Exception {
RedisTestBinder binder = getBinder();
ConsumerProperties consumerProperties = createConsumerProperties();
consumerProperties.setHeaderMode(HeaderMode.raw);
consumerProperties.setConcurrency(2);
consumerProperties.setInstanceIndex(0);
consumerProperties.setInstanceCount(3);
consumerProperties.setPartitioned(true);
QueueChannel input0 = new QueueChannel();
input0.setBeanName("test.input0S");
Binding<MessageChannel> input0Binding = binder.bindConsumer("part.0", "test", input0, consumerProperties);
consumerProperties.setInstanceIndex(1);
QueueChannel input1 = new QueueChannel();
input1.setBeanName("test.input1S");
Binding<MessageChannel> input1Binding = binder.bindConsumer("part.0", "test", input1, consumerProperties);
consumerProperties.setInstanceIndex(2);
QueueChannel input2 = new QueueChannel();
input2.setBeanName("test.input2S");
Binding<MessageChannel> input2Binding = binder.bindConsumer("part.0", "test", input2, consumerProperties);
ProducerProperties properties = createProducerProperties();
properties.setHeaderMode(HeaderMode.raw);
properties.setPartitionKeyExpression(spelExpressionParser.parseExpression("payload[0]"));
properties.setPartitionSelectorExpression(spelExpressionParser.parseExpression("hashCode()"));
properties.setPartitionCount(3);
DirectChannel output = new DirectChannel();
output.setBeanName("test.output");
Binding<MessageChannel> outputBinding = binder.bindProducer("part.0", output, properties);
try {
AbstractEndpoint endpoint = extractEndpoint(outputBinding);
assertThat(getEndpointRouting(endpoint), containsString("part.0.test-' + headers['partition']"));
}
catch (UnsupportedOperationException ignored) {
}
Message<byte[]> message2 = MessageBuilder.withPayload(new byte[]{2})
.setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "foo")
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, 42)
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, 43)
.build();
output.send(message2);
output.send(new GenericMessage<>(new byte[]{1}));
output.send(new GenericMessage<>(new byte[]{0}));
Message<?> receive0 = receive(input0);
assertNotNull(receive0);
Message<?> receive1 = receive(input1);
assertNotNull(receive1);
Message<?> receive2 = receive(input2);
assertNotNull(receive2);
assertThat(Arrays.asList(
((byte[]) receive0.getPayload())[0],
((byte[]) receive1.getPayload())[0],
((byte[]) receive2.getPayload())[0]),
containsInAnyOrder((byte)0, (byte)1, (byte)2));
input0Binding.unbind();
input1Binding.unbind();
input2Binding.unbind();
outputBinding.unbind();
}