本文整理汇总了Java中com.amazonaws.services.sqs.AmazonSQSAsyncClient类的典型用法代码示例。如果您正苦于以下问题:Java AmazonSQSAsyncClient类的具体用法?Java AmazonSQSAsyncClient怎么用?Java AmazonSQSAsyncClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmazonSQSAsyncClient类属于com.amazonaws.services.sqs包,在下文中一共展示了AmazonSQSAsyncClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Override
public void start() {
try {
if (this.encoder == null) {
addStatus(new ErrorStatus("No encoder set for the appender named \"" + name + "\".", this));
return;
}
close();
this.sqs = new AmazonSQSAsyncClient(getCredentials(),
this.threadPool > 0 ? Executors.newFixedThreadPool(this.threadPool)
: Executors.newCachedThreadPool());
this.sqs.setEndpoint(new URI(this.queueUrl).getHost());
this.encoder.init(new SqsOutputStreamAdapter());
super.start();
} catch (Exception e) {
addError(this.getClass() + " start failure", e);
}
}
示例2: initialize
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Override
public void initialize(JSONObject config) throws Exception {
String endpoint = config.getString(PARAM_ENDPOINT);
String queueName = config.getString(GenericQueue.PARAM_NAME);
String accessKey = config.getString(PARAM_ACCESS_KEY);
String secretKey = config.getString(PARAM_SECRET_KEY);
if(accessKey==null) throw new Exception(PARAM_ACCESS_KEY+" is required!");
if(secretKey==null) throw new Exception(PARAM_SECRET_KEY+" is required!");
try {
this.client = new AmazonSQSAsyncClient(new BasicAWSCredentials(accessKey,secretKey));
this.client.setEndpoint(endpoint);
CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName);
CreateQueueResult createQueueResult = this.client.createQueue(createQueueRequest);
this.queueUrl = createQueueResult.getQueueUrl();
} catch (Throwable e){
throw new Exception(e);
}
}
示例3: configure
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Override
protected void configure() {
Region region = Region.getRegion(config.get(Regions.class, REGION_CONFIG_KEY));
AmazonSQSAsyncClient amazonSQSAsyncClient = new AmazonSQSAsyncClient();
amazonSQSAsyncClient.setRegion(region);
bind(AmazonSQSAsyncClient.class).toInstance(amazonSQSAsyncClient);
// Thread pool setup. Include a queue the size of the pool.
// Always add headroom for admin in QueueManager
int numWorkers = config.get(Integer.class, NUM_THREADS_CONFIG_KEY);
int poolThreads = numWorkers + QUEUE_MANAGER_HEADROOM;
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(poolThreads, poolThreads, 0L,
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(numWorkers));
threadPoolExecutor.prestartAllCoreThreads();
bind(ExecutorService.class).toInstance(threadPoolExecutor);
bind(ThreadPoolExecutor.class).toInstance(threadPoolExecutor);
bind(Dispatcher.class).asEagerSingleton();
bind(Enqueuer.class).asEagerSingleton();
bind(QueueManager.class).asEagerSingleton();
}
示例4: configuration_withMinimalBeans_shouldStartSqsListenerContainer
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的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"));
}
示例5: parseInternal_minimalConfiguration_createsBufferedClientWithoutExplicitTaskExecutor
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Test
public void parseInternal_minimalConfiguration_createsBufferedClientWithoutExplicitTaskExecutor() throws Exception {
//Arrange
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
//Act
reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-minimal.xml", getClass()));
//Assert
AmazonSQSBufferedAsyncClient sqsBufferedAsyncClient = beanFactory.getBean("customClient", AmazonSQSBufferedAsyncClient.class);
AmazonSQSAsyncClient asyncClient = (AmazonSQSAsyncClient) ReflectionTestUtils.getField(sqsBufferedAsyncClient, "realSQS");
assertNotNull(asyncClient);
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) ReflectionTestUtils.getField(asyncClient, "executorService");
assertEquals(50, threadPoolExecutor.getCorePoolSize());
}
示例6: parseInternal_withCustomTasExecutor_createsBufferedClientWithCustomTaskExecutor
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Test
public void parseInternal_withCustomTasExecutor_createsBufferedClientWithCustomTaskExecutor() 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
AmazonSQSBufferedAsyncClient sqsBufferedAsyncClient = beanFactory.getBean("customClient", AmazonSQSBufferedAsyncClient.class);
AmazonSQSAsyncClient asyncClient = (AmazonSQSAsyncClient) ReflectionTestUtils.getField(sqsBufferedAsyncClient, "realSQS");
assertNotNull(asyncClient);
ShutdownSuppressingExecutorServiceAdapter executor = (ShutdownSuppressingExecutorServiceAdapter) ReflectionTestUtils.getField(asyncClient, "executorService");
assertSame(beanFactory.getBean("myThreadPoolTaskExecutor"), ReflectionTestUtils.getField(executor, "taskExecutor"));
}
示例7: postConstruct_queuePropertyContainsNonExistentQueue_createsQueue
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Test
public void postConstruct_queuePropertyContainsNonExistentQueue_createsQueue() throws Exception {
// ARRANGE
setupConfig();
sqsAsyncClientMock = createMock(AmazonSQSAsyncClient.class);
for (String queueName : new String[] { "foo", "bar" }) {
expect(sqsAsyncClientMock.getQueueUrl(queueName))
.andReturn(new GetQueueUrlResult().withQueueUrl(queueName + ".queueUrl")).once();
}
expect(sqsAsyncClientMock.getQueueUrl("baz")).andThrow(new QueueDoesNotExistException("lol")).once();
expect(sqsAsyncClientMock.createQueue("baz")).andReturn(new CreateQueueResult().withQueueUrl("baz.queueurl")).once();
FieldUtils.writeField(this.queueManager, "sqsClient", sqsAsyncClientMock, true);
setupExecutorService();
replay(configMock, sqsAsyncClientMock, executorServiceMock);
// ACT
this.queueManager.postConstruct();
// ASSERT
verify(configMock, sqsAsyncClientMock, executorServiceMock);
}
示例8: setupQueueClient
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
private void setupQueueClient() throws Exception {
sqsAsyncClientMock = createMock(AmazonSQSAsyncClient.class);
for (String queueName : new String[] { "foo", "bar", "baz"}) {
expect(sqsAsyncClientMock.getQueueUrl(queueName))
.andReturn(new GetQueueUrlResult().withQueueUrl(queueName + ".queueUrl")).once();
}
FieldUtils.writeField(this.queueManager, "sqsClient", sqsAsyncClientMock, true);
}
示例9: doStart
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Override
protected void doStart() {
sqs = new AmazonSQSAsyncClient(
getCredentials(),
getClientConfiguration(),
Executors.newFixedThreadPool(getThreadPoolSize())
);
sqs.setEndpoint(getEndpoint());
}
示例10: amazonSQS
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Lazy
@Bean(destroyMethod = "shutdown")
public AmazonSQSBufferedAsyncClient amazonSQS() throws Exception {
AmazonWebserviceClientFactoryBean<AmazonSQSAsyncClient> clientFactoryBean = new AmazonWebserviceClientFactoryBean<>(AmazonSQSAsyncClient.class,
this.awsCredentialsProvider,
this.regionProvider);
clientFactoryBean.afterPropertiesSet();
return new AmazonSQSBufferedAsyncClient(clientFactoryBean.getObject());
}
示例11: configuration_withoutAwsCredentials_shouldCreateAClientWithDefaultCredentialsProvider
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Test
public void configuration_withoutAwsCredentials_shouldCreateAClientWithDefaultCredentialsProvider() throws Exception {
// Arrange & Act
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConfigurationWithMissingAwsCredentials.class);
// Assert
AmazonSQSBufferedAsyncClient bufferedAmazonSqsClient = applicationContext.getBean(AmazonSQSBufferedAsyncClient.class);
AmazonSQSAsyncClient amazonSqsClient = (AmazonSQSAsyncClient) ReflectionTestUtils.getField(bufferedAmazonSqsClient, "realSQS");
assertTrue(DefaultAWSCredentialsProviderChain.class.isInstance(ReflectionTestUtils.getField(amazonSqsClient, "awsCredentialsProvider")));
}
示例12: configuration_withRegionProvider_shouldUseItForClient
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Test
public void configuration_withRegionProvider_shouldUseItForClient() throws Exception {
// Arrange & Act
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConfigurationWithRegionProvider.class);
AmazonSQSAsync bufferedAmazonSqsClient = applicationContext.getBean(AmazonSQSAsync.class);
AmazonSQSAsyncClient amazonSqs = (AmazonSQSAsyncClient) ReflectionTestUtils.getField(bufferedAmazonSqsClient, "realSQS");
// Assert
assertEquals("https://" + Region.getRegion(Regions.EU_WEST_1).getServiceEndpoint("sqs"), ReflectionTestUtils.getField(amazonSqs, "endpoint").toString());
}
示例13: DefaultListableBeanFactory
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Test
public void parseInternal_withMultipleMessagingTemplatesDefined_shouldConfigureOnlyOneSqsClientAndDecorateOnlyOnce() throws Exception {
//Arrange
DefaultListableBeanFactory registry = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);
//Act
reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-multiple-templates.xml", getClass()));
//Assert
AmazonSQSBufferedAsyncClient amazonSqs = registry.getBean(AmazonSQSBufferedAsyncClient.class);
assertTrue(ReflectionTestUtils.getField(amazonSqs, "realSQS") instanceof AmazonSQSAsyncClient);
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:14,代码来源:QueueMessagingTemplateBeanDefinitionParserTest.java
示例14: parseInternal_notBuffered_createsAsyncClientWithoutBufferedDecorator
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
@Test
public void parseInternal_notBuffered_createsAsyncClientWithoutBufferedDecorator() throws Exception {
//Arrange
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
//Act
reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-not-buffered.xml", getClass()));
//Assert
AmazonSQSAsyncClient asyncClient = beanFactory.getBean("customClient", AmazonSQSAsyncClient.class);
assertNotNull(asyncClient);
assertTrue(AmazonSQSAsyncClient.class.isInstance(asyncClient));
}
示例15: createInstance
import com.amazonaws.services.sqs.AmazonSQSAsyncClient; //导入依赖的package包/类
/**
* Creates Amazon SQS client for given endpoint using the provided credentials.
*
* @param awsCredentials AWS credentials with access to the endpoint, or null to use default aws credentials.
* @return Amazon SQS client.
*/
private static AmazonSQSAsync createInstance(AWSCredentials awsCredentials) {
if (awsCredentials == null) {
return new AmazonSQSAsyncClient();
} else {
return new AmazonSQSAsyncClient(awsCredentials);
}
}