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


Java AcknowledgeMode类代码示例

本文整理汇总了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;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:23,代码来源:AmqpConfig.java

示例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;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:22,代码来源:AmqpConfig.java

示例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;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:23,代码来源:AmqpConfig.java

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

示例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;
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:12,代码来源:AmqpConfiguration.java

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

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

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

示例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"));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:20,代码来源:RabbitAutoConfigurationTests.java

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

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

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


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