本文整理汇总了Java中com.amazonaws.services.sqs.AmazonSQSClientBuilder类的典型用法代码示例。如果您正苦于以下问题:Java AmazonSQSClientBuilder类的具体用法?Java AmazonSQSClientBuilder怎么用?Java AmazonSQSClientBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmazonSQSClientBuilder类属于com.amazonaws.services.sqs包,在下文中一共展示了AmazonSQSClientBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
/**
* Loads the test-specific Log4J configuration and resets the environment.
*/
public void setUp(String propertiesName)
throws Exception
{
URL config = ClassLoader.getSystemResource(propertiesName);
assertNotNull("missing configuration: " + propertiesName, config);
LogManager.resetConfiguration();
PropertyConfigurator.configure(config);
localLogger = Logger.getLogger(getClass());
runId = String.valueOf(System.currentTimeMillis());
resourceName = "SNSAppenderIntegrationTest-" + runId;
System.setProperty("SNSAppenderIntegrationTest.resourceName", resourceName);
localSNSclient = AmazonSNSClientBuilder.defaultClient();
localSQSclient = AmazonSQSClientBuilder.defaultClient();
}
示例2: getClient
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
/**
* Returns a client instance for AWS SQS.
* @return a client that talks to SQS
*/
public static AmazonSQS getClient() {
if (sqsClient != null) {
return sqsClient;
}
if (Config.IN_PRODUCTION) {
sqsClient = AmazonSQSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(Config.AWS_ACCESSKEY, Config.AWS_SECRETKEY))).
withRegion(Config.AWS_REGION).build();
} else {
sqsClient = AmazonSQSClientBuilder.standard().
withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("x", "x"))).
withEndpointConfiguration(new EndpointConfiguration(LOCAL_ENDPOINT, "")).build();
}
Para.addDestroyListener(new DestroyListener() {
public void onDestroy() {
sqsClient.shutdown();
}
});
return sqsClient;
}
示例3: changeMessageVisibilityMultiple
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
public static void changeMessageVisibilityMultiple(
String queue_url, int timeout)
{
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
List<ChangeMessageVisibilityBatchRequestEntry> entries =
new ArrayList<ChangeMessageVisibilityBatchRequestEntry>();
entries.add(new ChangeMessageVisibilityBatchRequestEntry(
"unique_id_msg1",
sqs.receiveMessage(queue_url)
.getMessages()
.get(0)
.getReceiptHandle())
.withVisibilityTimeout(timeout));
entries.add(new ChangeMessageVisibilityBatchRequestEntry(
"unique_id_msg2",
sqs.receiveMessage(queue_url)
.getMessages()
.get(0)
.getReceiptHandle())
.withVisibilityTimeout(timeout + 200));
sqs.changeMessageVisibilityBatch(queue_url, entries);
}
示例4: CloudtrailSQSClient
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
public CloudtrailSQSClient(Region region, String queueName, AWSAuthProvider authProvider, HttpUrl proxyUrl, ObjectMapper objectMapper) {
AmazonSQSClientBuilder clientBuilder = AmazonSQSClientBuilder.standard().withRegion(region.getName()).withCredentials(authProvider);
if (proxyUrl != null) {
clientBuilder.withClientConfiguration(Proxy.forAWS(proxyUrl));
}
this.sqs = clientBuilder.build();
this.queueName = queueName;
this.objectMapper = objectMapper;
}
示例5: sqsConnectionFactory
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
@Bean
public SQSConnectionFactory sqsConnectionFactory() throws JMSException {
return new SQSConnectionFactory(
new ProviderConfiguration(),
AmazonSQSClientBuilder.standard()
.withRegion(Regions.AP_SOUTHEAST_2)
.withCredentials(new ProfileCredentialsProvider(CREDENTIALS_PROVIDER))
);
}
示例6: createSqsClient
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
public static AmazonSQS createSqsClient(AWSCredentials credentials, ClientConfiguration cc, Regions region) {
return AmazonSQSClientBuilder //
.standard() //
.withCredentials(new AWSStaticCredentialsProvider(credentials)) //
.withRegion(region) //
.build();
}
示例7: initializeSqs
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
private AmazonSQS initializeSqs() {
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretyKey);
AWSStaticCredentialsProvider provider = new AWSStaticCredentialsProvider(awsCredentials);
return AmazonSQSClientBuilder.standard()
.withCredentials(provider)
.withRegion(Regions.US_EAST_2)
.build();
}
示例8: get
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
@Override
public AmazonSQS get(SqsModule.EndpointConfig config) {
AmazonSQSClientBuilder builder = AmazonSQSClientBuilder.standard();
builder.withCredentials(credentialsProvider);
if (config.endpoint().isPresent()) {
builder.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegionName())
);
} else {
builder.withRegion(Regions.fromName(config.getRegionName()));
}
return builder.build();
}
示例9: init
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
private void init() {
AWSCredentials awsCredentials = new BasicAWSCredentials(configuration.getAccessKeyId(), configuration.getSecretAccessKey());
AmazonSQS sqs = AmazonSQSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.withRegion(Regions.fromName(configuration.getRegion())).build();
this.sqsMessageHandler = new SqsMessageHandler(sqs);
}
示例10: changeMessageVisibilitySingle
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
public static void changeMessageVisibilitySingle(
String queue_url, int timeout)
{
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
// Get the receipt handle for the first message in the queue.
String receipt = sqs.receiveMessage(queue_url)
.getMessages()
.get(0)
.getReceiptHandle();
sqs.changeMessageVisibility(queue_url, receipt, timeout);
}
示例11: main
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
public static void main(String[] args)
{
final String queue_name = "testQueue" + new Date().getTime();
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
// first, create a queue (unless it exists already)
try {
CreateQueueResult cq_result = sqs.createQueue(queue_name);
} catch (AmazonSQSException e) {
if (!e.getErrorCode().equals("QueueAlreadyExists")) {
throw e;
}
}
final String queue_url = sqs.getQueueUrl(queue_name).getQueueUrl();
// Send some messages to the queue
for (int i = 0; i < 20; i++) {
sqs.sendMessage(queue_url, "This is message " + i);
}
// change visibility timeout (single)
changeMessageVisibilitySingle(queue_url, 3600);
// change visibility timeout (multiple)
changeMessageVisibilityMultiple(queue_url, 2000);
}
示例12: main
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
public static void main(String[] args)
{
final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
try {
CreateQueueResult create_result = sqs.createQueue(QUEUE_NAME);
} catch (AmazonSQSException e) {
if (!e.getErrorCode().equals("QueueAlreadyExists")) {
throw e;
}
}
String queueUrl = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();
SendMessageRequest send_msg_request = new SendMessageRequest()
.withQueueUrl(queueUrl)
.withMessageBody("hello world")
.withDelaySeconds(5);
sqs.sendMessage(send_msg_request);
// Send multiple messages to the queue
SendMessageBatchRequest send_batch_request = new SendMessageBatchRequest()
.withQueueUrl(queueUrl)
.withEntries(
new SendMessageBatchRequestEntry(
"msg_1", "Hello from message 1"),
new SendMessageBatchRequestEntry(
"msg_2", "Hello from message 2")
.withDelaySeconds(10));
sqs.sendMessageBatch(send_batch_request);
// receive messages from the queue
List<Message> messages = sqs.receiveMessage(queueUrl).getMessages();
// delete messages from the queue
for (Message m : messages) {
sqs.deleteMessage(queueUrl, m.getReceiptHandle());
}
}
示例13: buildSqsClient
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
private void buildSqsClient() {
if (sqsClient == null) {
sqsClient = AmazonSQSClientBuilder.standard()
.withCredentials(config.getAwsCredentialsProvider())
.withRegion(config.getSqsRegion())
.build();
}
}
示例14: SQSConnectionFactory
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
public SQSConnectionFactory(ProviderConfiguration providerConfiguration, final AmazonSQSClientBuilder clientBuilder) {
if (providerConfiguration == null) {
throw new IllegalArgumentException("Provider configuration cannot be null");
}
if (clientBuilder == null) {
throw new IllegalArgumentException("AmazonSQS client builder cannot be null");
}
this.providerConfiguration = providerConfiguration;
this.amazonSQSClientSupplier = new AmazonSQSClientSupplier() {
@Override
public AmazonSQS get() {
return clientBuilder.build();
}
};
}
示例15: canCreateFactoryWithCustomBuilder
import com.amazonaws.services.sqs.AmazonSQSClientBuilder; //导入依赖的package包/类
@Test
public void canCreateFactoryWithCustomBuilder() throws JMSException {
AmazonSQSClientBuilder clientBuilder = AmazonSQSClientBuilder.standard().withRegion(Regions.US_EAST_1);
SQSConnectionFactory factory = new SQSConnectionFactory(new ProviderConfiguration(), clientBuilder);
SQSConnection connection = factory.createConnection();
connection.close();
}