本文整理汇总了Java中org.springframework.amqp.core.AcknowledgeMode类的典型用法代码示例。如果您正苦于以下问题:Java AcknowledgeMode类的具体用法?Java AcknowledgeMode怎么用?Java AcknowledgeMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AcknowledgeMode类属于org.springframework.amqp.core包,在下文中一共展示了AcknowledgeMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: messageContainer
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Bean
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "host")
public SimpleMessageListenerContainer messageContainer() {
SimpleMessageListenerContainer container =
new SimpleMessageListenerContainer(connectionFactory);
container.setQueues(queue());
container.setExposeListenerChannel(true);
container.setMaxConcurrentConsumers(2);
container.setConcurrentConsumers(1);
//设置确认模式手工确认
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
container.setMessageListener((ChannelAwareMessageListener) (message, channel) -> {
byte[] messageBody = message.getBody();
LOGGER.debug("motan 框架接收到的消息");
//确认消息成功消费
final Boolean success = mythMqReceiveService.processMessage(messageBody);
if (success) {
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
});
return container;
}
示例2: messageContainer
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Bean
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "host")
public SimpleMessageListenerContainer messageContainer() {
SimpleMessageListenerContainer container =
new SimpleMessageListenerContainer(connectionFactory);
container.setQueues(queue());
container.setExposeListenerChannel(true);
container.setMaxConcurrentConsumers(1);
container.setConcurrentConsumers(1);
//设置确认模式手工确认
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
container.setMessageListener((ChannelAwareMessageListener) (message, channel) -> {
byte[] messageBody = message.getBody();
//确认消息成功消费
final Boolean success = mythMqReceiveService.processMessage(messageBody);
if (success) {
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
});
return container;
}
示例3: messageContainer
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Bean
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "host")
public SimpleMessageListenerContainer messageContainer() {
SimpleMessageListenerContainer container =
new SimpleMessageListenerContainer(connectionFactory);
container.setQueues(queue());
container.setExposeListenerChannel(true);
container.setMaxConcurrentConsumers(3);
container.setConcurrentConsumers(1);
//设置确认模式手工确认
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
container.setMessageListener((ChannelAwareMessageListener) (message, channel) -> {
byte[] messageBody = message.getBody();
LogUtil.debug(LOGGER,()->"springcloud account服务 amqp接收消息");
//确认消息成功消费
final Boolean success = mythMqReceiveService.processMessage(messageBody);
if (success) {
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
});
return container;
}
示例4: verifyContainer
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
private SimpleMessageListenerContainer verifyContainer(Lifecycle endpoint) {
SimpleMessageListenerContainer container;
RetryTemplate retry;
container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer",
SimpleMessageListenerContainer.class);
assertThat(container.getAcknowledgeMode()).isEqualTo(AcknowledgeMode.NONE);
assertThat(container.getQueueNames()[0]).startsWith("foo.props.0");
assertThat(TestUtils.getPropertyValue(container, "transactional", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(container, "concurrentConsumers")).isEqualTo(2);
assertThat(TestUtils.getPropertyValue(container, "maxConcurrentConsumers")).isEqualTo(3);
assertThat(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(container, "prefetchCount")).isEqualTo(20);
assertThat(TestUtils.getPropertyValue(container, "txSize")).isEqualTo(10);
retry = TestUtils.getPropertyValue(endpoint, "retryTemplate", RetryTemplate.class);
assertThat(TestUtils.getPropertyValue(retry, "retryPolicy.maxAttempts")).isEqualTo(23);
assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.initialInterval")).isEqualTo(2000L);
assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.maxInterval")).isEqualTo(20000L);
assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.multiplier")).isEqualTo(5.0);
List<?> requestMatchers = TestUtils.getPropertyValue(endpoint, "headerMapper.requestHeaderMatcher.matchers",
List.class);
assertThat(requestMatchers).hasSize(1);
assertThat(TestUtils.getPropertyValue(requestMatchers.get(0), "pattern")).isEqualTo("foo");
return container;
}
示例5: ticketingServiceListenerContainer
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
/**
* This bean instantiates and returns the Simple message
* listener container.
*
* @return Simple message listener container
*/
@Bean
SimpleMessageListenerContainer ticketingServiceListenerContainer()
{
final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(rabbitConnectionFactory);
container.setAcknowledgeMode(AcknowledgeMode.AUTO);
container.setQueues(ticketServiceRequestQueue);
container.setMessageListener(ticketingServiceListener());
container.setErrorHandler(new DefaultContainerErrorHandler("ticketingServiceListenerContainer"));
return container;
}
开发者ID:dellemc-symphony,项目名称:ticketing-service-paqx-parent-sample,代码行数:18,代码来源:TicketingServiceConsumerConfig.java
示例6: messageContainer
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Bean
public SimpleMessageListenerContainer messageContainer(ConnectionFactory connectionFactory, MessageListenerAdapter messageListenerAdapter) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
container.setQueues(this.queue);
container.setExposeListenerChannel(true);
container.setMaxConcurrentConsumers(this.maxConcurrentConsumers);
container.setConcurrentConsumers(this.concurrentConsumers);
container.setAcknowledgeMode(AcknowledgeMode.AUTO);
container.setMessageListener(messageListenerAdapter);
return container;
}
示例7: test
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Test
public void test() throws Exception {
Advice[] adviceChain = TestUtils.getPropertyValue(this.container, "adviceChain", Advice[].class);
assertEquals(1, adviceChain.length);
RetryTemplate retryTemplate = TestUtils.getPropertyValue(adviceChain[0], "retryOperations",
RetryTemplate.class);
assertEquals(5, TestUtils.getPropertyValue(retryTemplate, "retryPolicy.maxAttempts"));
assertEquals(123L, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.initialInterval"));
assertEquals(345L, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.maxInterval"));
assertEquals(1.5, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.multiplier"));
assertEquals("scsapp-testq", this.container.getQueueNames()[0]);
assertFalse(TestUtils.getPropertyValue(this.container, "defaultRequeueRejected", Boolean.class));
assertEquals(2, TestUtils.getPropertyValue(this.container, "concurrentConsumers"));
assertEquals(3, TestUtils.getPropertyValue(this.container, "maxConcurrentConsumers"));
assertEquals(AcknowledgeMode.NONE, TestUtils.getPropertyValue(this.container, "acknowledgeMode"));
assertEquals(10, TestUtils.getPropertyValue(this.container, "prefetchCount"));
assertEquals(5, TestUtils.getPropertyValue(this.container, "txSize"));
this.rabbitTemplate.convertAndSend("", "scsapp-testq", "foo", new MessagePostProcessor() {
@Override
public org.springframework.amqp.core.Message postProcessMessage(
org.springframework.amqp.core.Message message) throws AmqpException {
message.getMessageProperties().getHeaders().put("bar", "baz");
return message;
}
});
Message<?> out = this.messageCollector.forChannel(this.channels.output()).poll(10, TimeUnit.SECONDS);
assertNotNull(out);
assertEquals("foo", out.getPayload());
assertEquals("baz", out.getHeaders().get("bar"));
assertNull(out.getHeaders().get(AmqpHeaders.DELIVERY_MODE));
}
示例8: test
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Test
public void test() throws Exception {
Advice[] adviceChain = TestUtils.getPropertyValue(this.container, "adviceChain", Advice[].class);
assertEquals(1, adviceChain.length);
RetryTemplate retryTemplate = TestUtils.getPropertyValue(adviceChain[0], "retryOperations",
RetryTemplate.class);
assertEquals(5, TestUtils.getPropertyValue(retryTemplate, "retryPolicy.maxAttempts"));
assertEquals(123L, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.initialInterval"));
assertEquals(345L, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.maxInterval"));
assertEquals(1.5, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.multiplier"));
assertEquals("scsapp-testq", this.container.getQueueNames()[0]);
assertFalse(TestUtils.getPropertyValue(this.container, "defaultRequeueRejected", Boolean.class));
assertEquals(2, TestUtils.getPropertyValue(this.container, "concurrentConsumers"));
assertEquals(3, TestUtils.getPropertyValue(this.container, "maxConcurrentConsumers"));
assertEquals(AcknowledgeMode.NONE, TestUtils.getPropertyValue(this.container, "acknowledgeMode"));
assertEquals(10, TestUtils.getPropertyValue(this.container, "prefetchCount"));
assertEquals(5, TestUtils.getPropertyValue(this.container, "txSize"));
this.rabbitTemplate.convertAndSend("", "scsapp-testq", "foo", new MessagePostProcessor() {
@Override
public org.springframework.amqp.core.Message postProcessMessage(
org.springframework.amqp.core.Message message) throws AmqpException {
message.getMessageProperties().getHeaders().put("bar", "baz");
return message;
}
});
Message<?> out = this.messageCollector.forChannel(this.channels.output()).poll(10, TimeUnit.SECONDS);
assertNotNull(out);
assertEquals("foo", out.getPayload());
assertEquals("baz", out.getHeaders().get("bar"));
assertNull(out.getHeaders().get(AmqpHeaders.DELIVERY_MODE));
}
示例9: listenerContainer
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Bean
public SimpleMessageListenerContainer listenerContainer() {
SimpleMessageListenerContainer bean = new SimpleMessageListenerContainer(connectionFactory());
bean.setMessageListener(messageListener);
bean.setQueues(queue());
bean.setAcknowledgeMode(AcknowledgeMode.AUTO);
return bean;
}
示例10: testRabbitListenerContainerFactoryWithCustomSettings
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Test
public void testRabbitListenerContainerFactoryWithCustomSettings() {
load(TestConfiguration.class, "spring.rabbitmq.listener.autoStartup:false",
"spring.rabbitmq.listener.acknowledgeMode:manual",
"spring.rabbitmq.listener.concurrency:5",
"spring.rabbitmq.listener.maxConcurrency:10",
"spring.rabbitmq.listener.prefetch=40",
"spring.rabbitmq.listener.transactionSize:20");
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context
.getBean("rabbitListenerContainerFactory",
SimpleRabbitListenerContainerFactory.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitListenerContainerFactory);
assertEquals(false, dfa.getPropertyValue("autoStartup"));
assertEquals(AcknowledgeMode.MANUAL, dfa.getPropertyValue("acknowledgeMode"));
assertEquals(5, dfa.getPropertyValue("concurrentConsumers"));
assertEquals(10, dfa.getPropertyValue("maxConcurrentConsumers"));
assertEquals(40, dfa.getPropertyValue("prefetchCount"));
assertEquals(20, dfa.getPropertyValue("txSize"));
}
示例11: simpleMessageListenerContainer
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Bean(destroyMethod = "destroy")
public SimpleMessageListenerContainer simpleMessageListenerContainer() {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
container.setQueues(queue());
container.setMessageListener(loggingMessageListenerAdapter());
container.setAcknowledgeMode(AcknowledgeMode.AUTO);
return container;
}
示例12: rabbitListenerContainerFactory
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
// factory.setPrefetchCount(5);
factory.setAcknowledgeMode(AcknowledgeMode.AUTO);
return factory;
}
示例13: getAcknowledgeMode
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
public AcknowledgeMode getAcknowledgeMode() {
return this.acknowledgeMode;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:4,代码来源:RabbitProperties.java
示例14: setAcknowledgeMode
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) {
this.acknowledgeMode = acknowledgeMode;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:4,代码来源:RabbitProperties.java
示例15: testConsumerProperties
import org.springframework.amqp.core.AcknowledgeMode; //导入依赖的package包/类
@Test
public void testConsumerProperties() throws Exception {
RabbitTestBinder binder = getBinder();
ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties();
properties.getExtension().setRequeueRejected(true);
properties.getExtension().setTransacted(true);
properties.getExtension().setExclusive(true);
properties.getExtension().setMissingQueuesFatal(true);
properties.getExtension().setFailedDeclarationRetryInterval(1500L);
properties.getExtension().setQueueDeclarationRetries(23);
Binding<MessageChannel> consumerBinding = binder.bindConsumer("props.0", null,
createBindableChannel("input", new BindingProperties()), properties);
Lifecycle endpoint = extractEndpoint(consumerBinding);
SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer",
SimpleMessageListenerContainer.class);
assertThat(container.getAcknowledgeMode()).isEqualTo(AcknowledgeMode.AUTO);
assertThat(container.getQueueNames()[0]).startsWith(properties.getExtension().getPrefix());
assertThat(TestUtils.getPropertyValue(container, "transactional", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(container, "exclusive", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(container, "concurrentConsumers")).isEqualTo(1);
assertThat(TestUtils.getPropertyValue(container, "maxConcurrentConsumers")).isNull();
assertThat(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(container, "prefetchCount")).isEqualTo(1);
assertThat(TestUtils.getPropertyValue(container, "txSize")).isEqualTo(1);
assertThat(TestUtils.getPropertyValue(container, "missingQueuesFatal", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(container, "failedDeclarationRetryInterval")).isEqualTo(1500L);
assertThat(TestUtils.getPropertyValue(container, "declarationRetries")).isEqualTo(23);
RetryTemplate retry = TestUtils.getPropertyValue(endpoint, "retryTemplate", RetryTemplate.class);
assertThat(TestUtils.getPropertyValue(retry, "retryPolicy.maxAttempts")).isEqualTo(3);
assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.initialInterval")).isEqualTo(1000L);
assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.maxInterval")).isEqualTo(10000L);
assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.multiplier")).isEqualTo(2.0);
consumerBinding.unbind();
assertThat(endpoint.isRunning()).isFalse();
properties = createConsumerProperties();
properties.getExtension().setAcknowledgeMode(AcknowledgeMode.NONE);
properties.setBackOffInitialInterval(2000);
properties.setBackOffMaxInterval(20000);
properties.setBackOffMultiplier(5.0);
properties.setConcurrency(2);
properties.setMaxAttempts(23);
properties.getExtension().setMaxConcurrency(3);
properties.getExtension().setPrefix("foo.");
properties.getExtension().setPrefetch(20);
properties.getExtension().setHeaderPatterns(new String[] { "foo" });
properties.getExtension().setTxSize(10);
properties.setInstanceIndex(0);
consumerBinding = binder.bindConsumer("props.0", "test", createBindableChannel("input", new BindingProperties()),
properties);
endpoint = extractEndpoint(consumerBinding);
container = verifyContainer(endpoint);
assertThat(container.getQueueNames()[0]).isEqualTo("foo.props.0.test");
consumerBinding.unbind();
assertThat(endpoint.isRunning()).isFalse();
}