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


Java SimpleMessageListenerContainer类代码示例

本文整理汇总了Java中org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer的典型用法代码示例。如果您正苦于以下问题:Java SimpleMessageListenerContainer类的具体用法?Java SimpleMessageListenerContainer怎么用?Java SimpleMessageListenerContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SimpleMessageListenerContainer类属于org.springframework.cloud.aws.messaging.listener包,在下文中一共展示了SimpleMessageListenerContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractMaxNumberOfMessagesFromListenerContainer

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
private int extractMaxNumberOfMessagesFromListenerContainer(
        @NonNull SimpleMessageListenerContainer simpleMessageListenerContainer) {
    try {
        Field f = simpleMessageListenerContainer.getClass().getSuperclass().getDeclaredField(
                "maxNumberOfMessages");
        f.setAccessible(true);
        Integer maxNumberOfMessages = (Integer) f.get(simpleMessageListenerContainer);
        if (maxNumberOfMessages != null) {
            return maxNumberOfMessages;
        } else {
            // org.springframework.cloud.aws.messaging.listener.AbstractMessageListenerContainer.DEFAULT_MAX_NUMBER_OF_MESSAGES
            return 10;
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new IllegalStateException(
                "Cannot get BatchSize of SimpleMessageListenerContainer", e);
    }
}
 
开发者ID:Mercateo,项目名称:sqs-utils,代码行数:19,代码来源:LongRunningMessageHandlerFactory.java

示例2: configuration_withMinimalBeans_shouldStartSqsListenerContainer

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Test
public void configuration_withMinimalBeans_shouldStartSqsListenerContainer() throws Exception {
    // Arrange & Act
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MinimalConfiguration.class);
    SimpleMessageListenerContainer container = applicationContext.getBean(SimpleMessageListenerContainer.class);

    // Assert
    assertTrue(container.isRunning());
    QueueMessageHandler queueMessageHandler = applicationContext.getBean(QueueMessageHandler.class);
    assertTrue(QueueMessageHandler.class.isInstance(queueMessageHandler));

    HandlerMethodReturnValueHandler sendToReturnValueHandler = queueMessageHandler.getCustomReturnValueHandlers().get(0);
    QueueMessagingTemplate messagingTemplate = (QueueMessagingTemplate) ReflectionTestUtils.getField(sendToReturnValueHandler, "messageTemplate");
    AmazonSQSBufferedAsyncClient amazonBufferedSqsClient = (AmazonSQSBufferedAsyncClient) ReflectionTestUtils.getField(messagingTemplate, "amazonSqs");
    AmazonSQSAsyncClient amazonSqsClient = (AmazonSQSAsyncClient) ReflectionTestUtils.getField(amazonBufferedSqsClient, "realSQS");
    assertNotNull(ReflectionTestUtils.getField(amazonSqsClient, "awsCredentialsProvider"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:18,代码来源:SqsConfigurationTest.java

示例3: configuration_withCustomConfigurationFactory_shouldBeUsedToCreateTheContainer

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Test
public void configuration_withCustomConfigurationFactory_shouldBeUsedToCreateTheContainer() throws Exception {
    // Arrange & Act
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConfigurationWithCustomContainerFactory.class);
    SimpleMessageListenerContainer container = applicationContext.getBean(SimpleMessageListenerContainer.class);

    // Assert
    assertEquals(ConfigurationWithCustomContainerFactory.AMAZON_SQS, ReflectionTestUtils.getField(container, "amazonSqs"));
    assertEquals(ConfigurationWithCustomContainerFactory.AUTO_STARTUP, container.isAutoStartup());
    assertEquals(ConfigurationWithCustomContainerFactory.MAX_NUMBER_OF_MESSAGES, ReflectionTestUtils.getField(container, "maxNumberOfMessages"));
    assertEquals(ConfigurationWithCustomContainerFactory.MESSAGE_HANDLER, ReflectionTestUtils.getField(container, "messageHandler"));
    assertEquals(ConfigurationWithCustomContainerFactory.RESOURCE_ID_RESOLVER, ReflectionTestUtils.getField(container, "resourceIdResolver"));
    assertEquals(ConfigurationWithCustomContainerFactory.TASK_EXECUTOR, ReflectionTestUtils.getField(container, "taskExecutor"));
    assertEquals(ConfigurationWithCustomContainerFactory.VISIBILITY_TIMEOUT, ReflectionTestUtils.getField(container, "visibilityTimeout"));
    assertEquals(ConfigurationWithCustomContainerFactory.WAIT_TIME_OUT, ReflectionTestUtils.getField(container, "waitTimeOut"));
    assertTrue(ConfigurationWithCustomContainerFactory.DESTINATION_RESOLVER == ReflectionTestUtils.getField(container, "destinationResolver"));
    assertEquals(ConfigurationWithCustomContainerFactory.BACK_OFF_TIME, container.getBackOffTime());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:SqsConfigurationTest.java

示例4: parseInternal_customSqsClient_shouldProduceContainerWithCustomSqsClientUsed

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Test
public void parseInternal_customSqsClient_shouldProduceContainerWithCustomSqsClientUsed() throws Exception {
    //Arrange
    SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);

    //Act
    reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-custom-amazon-sqs.xml", getClass()));

    //Assert
    BeanDefinition sqsAsync = registry.getBeanDefinition("myClient");
    assertNotNull(sqsAsync);

    BeanDefinition abstractContainerDefinition = registry.getBeanDefinition(SimpleMessageListenerContainer.class.getName() + "#0");
    assertNotNull(abstractContainerDefinition);

    assertEquals(3, abstractContainerDefinition.getPropertyValues().size());
    assertEquals("myClient",
            ((RuntimeBeanReference) abstractContainerDefinition.getPropertyValues().getPropertyValue("amazonSqs").getValue()).getBeanName());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:21,代码来源:AnnotationDrivenQueueListenerBeanDefinitionParserTest.java

示例5: parseInternal_customTaskExecutor_shouldCreateContainerAndClientWithCustomTaskExecutor

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Test
public void parseInternal_customTaskExecutor_shouldCreateContainerAndClientWithCustomTaskExecutor() throws Exception {
    //Arrange
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

    //Act
    reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-custom-task-executor.xml", getClass()));

    //Assert
    BeanDefinition executor = beanFactory.getBeanDefinition("executor");
    assertNotNull(executor);

    BeanDefinition abstractContainerDefinition = beanFactory.getBeanDefinition(SimpleMessageListenerContainer.class.getName() + "#0");
    assertNotNull(abstractContainerDefinition);

    assertEquals(4, abstractContainerDefinition.getPropertyValues().size());
    assertEquals("executor",
            ((RuntimeBeanReference) abstractContainerDefinition.getPropertyValues().getPropertyValue("taskExecutor").getValue()).getBeanName());

    AmazonSQSBufferedAsyncClient bufferedAsyncClient = beanFactory.getBean(AmazonSQSBufferedAsyncClient.class);
    assertNotNull(bufferedAsyncClient);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:24,代码来源:AnnotationDrivenQueueListenerBeanDefinitionParserTest.java

示例6: parseInternal_withCustomProperties_customPropertiesConfiguredOnContainer

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Test
public void parseInternal_withCustomProperties_customPropertiesConfiguredOnContainer() throws Exception {
    //Arrange
    SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);

    //Act
    reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-custom-properties.xml", getClass()));

    //Assert
    BeanDefinition abstractContainerDefinition = registry.getBeanDefinition(SimpleMessageListenerContainer.class.getName() + "#0");
    assertNotNull(abstractContainerDefinition);

    assertEquals("false", abstractContainerDefinition.getPropertyValues().getPropertyValue("autoStartup").getValue());
    assertEquals("9", abstractContainerDefinition.getPropertyValues().getPropertyValue("maxNumberOfMessages").getValue());
    assertEquals("6", abstractContainerDefinition.getPropertyValues().getPropertyValue("visibilityTimeout").getValue());
    assertEquals("3", abstractContainerDefinition.getPropertyValues().getPropertyValue("waitTimeOut").getValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:AnnotationDrivenQueueListenerBeanDefinitionParserTest.java

示例7: LongRunningMessageHandlerFactory

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Inject
public LongRunningMessageHandlerFactory(
        @NonNull MessageHandlingRunnableFactory messageHandlingRunnableFactory,
        @NonNull VisibilityTimeoutExtenderFactory timeoutExtenderFactory,
        @NonNull QueueFactory queueFactory,
        @NonNull SimpleMessageListenerContainer simpleMessageListenerContainer) {
    this.messageHandlingRunnableFactory = messageHandlingRunnableFactory;
    this.timeoutExtenderFactory = timeoutExtenderFactory;
    this.queueFactory = queueFactory;

    this.executorService = Executors.newScheduledThreadPool(1);

    this.maxNumberOfMessagesPerBatch = extractMaxNumberOfMessagesFromListenerContainer(
            simpleMessageListenerContainer);
}
 
开发者ID:Mercateo,项目名称:sqs-utils,代码行数:16,代码来源:LongRunningMessageHandlerFactory.java

示例8: setUp

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer();
    uut = new LongRunningMessageHandlerFactory(messageHandlingRunnableFactory,
            timeoutExtenderFactory, queueFactory, simpleMessageListenerContainer);
}
 
开发者ID:Mercateo,项目名称:sqs-utils,代码行数:8,代码来源:LongRunningMessageHandlerFactoryTest.java

示例9: testConstructor_extractsTheCorrectMessageBatchSize

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Test
public void testConstructor_extractsTheCorrectMessageBatchSize() {
    // given
    SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer();
    simpleMessageListenerContainer.setMaxNumberOfMessages(2);

    // when
    uut = new LongRunningMessageHandlerFactory(messageHandlingRunnableFactory,
            timeoutExtenderFactory, queueFactory, simpleMessageListenerContainer);

    // then
    assertEquals(2, uut.maxNumberOfMessagesPerBatch);
}
 
开发者ID:Mercateo,项目名称:sqs-utils,代码行数:14,代码来源:LongRunningMessageHandlerFactoryTest.java

示例10: sqsMessageListenerContainer

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Bean
public SimpleMessageListenerContainer sqsMessageListenerContainer() {
  SimpleMessageListenerContainerFactory factory = sqsMessageListenerContainerFactory();
  SimpleMessageListenerContainer container = factory.createSimpleMessageListenerContainer();
  container.setMessageHandler(factory.getQueueMessageHandler());
  return container;
}
 
开发者ID:kalnee,项目名称:trivor,代码行数:8,代码来源:AWSConfig.java

示例11: createSimpleMessageListenerContainer

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
public SimpleMessageListenerContainer createSimpleMessageListenerContainer() {
    Assert.notNull(this.amazonSqs, "amazonSqs must not be null");

    SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer();
    simpleMessageListenerContainer.setAmazonSqs(this.amazonSqs);
    simpleMessageListenerContainer.setAutoStartup(this.autoStartup);

    if (this.taskExecutor != null) {
        simpleMessageListenerContainer.setTaskExecutor(this.taskExecutor);
    }
    if (this.maxNumberOfMessages != null) {
        simpleMessageListenerContainer.setMaxNumberOfMessages(this.maxNumberOfMessages);
    }
    if (this.visibilityTimeout != null) {
        simpleMessageListenerContainer.setVisibilityTimeout(this.visibilityTimeout);
    }
    if (this.waitTimeOut != null) {
        simpleMessageListenerContainer.setWaitTimeOut(this.waitTimeOut);
    }
    if (this.resourceIdResolver != null) {
        simpleMessageListenerContainer.setResourceIdResolver(this.resourceIdResolver);
    }
    if (this.destinationResolver != null) {
        simpleMessageListenerContainer.setDestinationResolver(this.destinationResolver);
    }
    if (this.backOffTime != null) {
        simpleMessageListenerContainer.setBackOffTime(this.backOffTime);
    }

    return simpleMessageListenerContainer;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:32,代码来源:SimpleMessageListenerContainerFactory.java

示例12: queueMessageHandlerBeanMustBeSetOnContainer

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Test
public void queueMessageHandlerBeanMustBeSetOnContainer() throws Exception {
    // Arrange & Act
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MinimalConfiguration.class);
    SimpleMessageListenerContainer simpleMessageListenerContainer = applicationContext.getBean(SimpleMessageListenerContainer.class);
    QueueMessageHandler queueMessageHandler = applicationContext.getBean(QueueMessageHandler.class);

    // Assert
    assertEquals(queueMessageHandler, ReflectionTestUtils.getField(simpleMessageListenerContainer, "messageHandler"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:11,代码来源:SqsConfigurationTest.java

示例13: parseInternal_minimalConfiguration_shouldProduceContainerWithDefaultAmazonSqsBean

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Test
public void parseInternal_minimalConfiguration_shouldProduceContainerWithDefaultAmazonSqsBean() throws Exception {
    //Act
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-minimal.xml", getClass());

    //Assert
    AmazonSQSAsync amazonSqsClient = applicationContext.getBean(AmazonSQSAsync.class);
    assertNotNull(amazonSqsClient);

    SimpleMessageListenerContainer container = applicationContext.getBean(SimpleMessageListenerContainer.class);
    assertNotNull(container);

    assertSame(amazonSqsClient, ReflectionTestUtils.getField(container, "amazonSqs"));
    assertSame(applicationContext.getBean(StackResourceRegistryDetectingResourceIdResolver.class), ReflectionTestUtils.getField(container, "resourceIdResolver"));

    QueueMessageHandler queueMessageHandler = (QueueMessageHandler) ReflectionTestUtils.getField(container, "messageHandler");
    HandlerMethodReturnValueHandler sendToReturnValueHandler = queueMessageHandler.getReturnValueHandlers().get(0);
    assertTrue(SendToHandlerMethodReturnValueHandler.class.isInstance(sendToReturnValueHandler));
    QueueMessagingTemplate queueMessagingTemplate = (QueueMessagingTemplate) ReflectionTestUtils.getField(sendToReturnValueHandler, "messageTemplate");

    assertTrue(CompositeMessageConverter.class.isInstance(queueMessagingTemplate.getMessageConverter()));

    @SuppressWarnings("unchecked")
    List<MessageConverter> messageConverters = (List<MessageConverter>) ReflectionTestUtils.getField(queueMessagingTemplate.getMessageConverter(), "converters");
    assertEquals(2, messageConverters.size());
    assertTrue(StringMessageConverter.class.isInstance(messageConverters.get(0)));
    assertTrue(MappingJackson2MessageConverter.class.isInstance(messageConverters.get(1)));

    StringMessageConverter stringMessageConverter = (StringMessageConverter) messageConverters.get(0);
    assertSame(String.class, stringMessageConverter.getSerializedPayloadClass());
    assertEquals(false, ReflectionTestUtils.getField(stringMessageConverter, "strictContentTypeMatch"));

    MappingJackson2MessageConverter jackson2MessageConverter = (MappingJackson2MessageConverter) messageConverters.get(1);
    assertSame(String.class, jackson2MessageConverter.getSerializedPayloadClass());
    assertEquals(false, ReflectionTestUtils.getField(jackson2MessageConverter, "strictContentTypeMatch"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:37,代码来源:AnnotationDrivenQueueListenerBeanDefinitionParserTest.java

示例14: parseInternal_customDestinationResolver_isUsedOnTheContainer

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Test
public void parseInternal_customDestinationResolver_isUsedOnTheContainer() throws Exception {
    // Arrange & Act
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-custom-destination-resolver.xml", getClass());

    // Assert
    SimpleMessageListenerContainer container = applicationContext.getBean(SimpleMessageListenerContainer.class);
    DestinationResolver<?> customDestinationResolver = applicationContext.getBean(DestinationResolver.class);
    assertTrue(customDestinationResolver == ReflectionTestUtils.getField(container, "destinationResolver"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:11,代码来源:AnnotationDrivenQueueListenerBeanDefinitionParserTest.java

示例15: parseInternal_definedBackOffTime_shouldBeSetOnContainer

import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer; //导入依赖的package包/类
@Test
public void parseInternal_definedBackOffTime_shouldBeSetOnContainer() throws Exception {
    // Arrange & Act
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-back-off-time.xml", getClass());

    // Assert
    SimpleMessageListenerContainer container = applicationContext.getBean(SimpleMessageListenerContainer.class);
    assertEquals(5000L, container.getBackOffTime());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:10,代码来源:AnnotationDrivenQueueListenerBeanDefinitionParserTest.java


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