本文整理汇总了Java中com.amazonaws.services.sqs.AmazonSQSAsync.setEndpoint方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonSQSAsync.setEndpoint方法的具体用法?Java AmazonSQSAsync.setEndpoint怎么用?Java AmazonSQSAsync.setEndpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.sqs.AmazonSQSAsync
的用法示例。
在下文中一共展示了AmazonSQSAsync.setEndpoint方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createQueueMessage
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入方法依赖的package包/类
SendMessageResult createQueueMessage(ImageCreateRequest request, Context context) {
LambdaLogger logger = context.getLogger();
final String queueName = request.getQueueName();
final String sqsEndpoint = request.getSqsEndpoint();
if (queueName == null || sqsEndpoint == null) {
logger.log("skip create queue. [" + request + "]");
return null;
}
AmazonSQSAsync client = createSQSClient();
client.setEndpoint(sqsEndpoint);
request.setSendMessageTimeMillis(System.currentTimeMillis());
try {
CreateQueueRequest req = new CreateQueueRequest(queueName);
String queueUrl = client.createQueue(req).getQueueUrl();
SendMessageRequest sendMessage = new SendMessageRequest();
sendMessage.setQueueUrl(queueUrl);
ObjectMapper om = new ObjectMapper();
sendMessage.setMessageBody(om.writeValueAsString(request));
Future<SendMessageResult> result = client.sendMessageAsync(sendMessage);
while (!result.isDone()) {
Thread.sleep(100);
}
return result.get();
} catch (Exception e) {
throw new RuntimeException("unexpected error occured in the create queue request.", e);
} finally {
client.shutdown();
}
}
示例2: deleteQueueMessage
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入方法依赖的package包/类
void deleteQueueMessage(Message message, ImageStateCheckAndPargeRequest request, Context context) {
AmazonSQSAsync client = createSQSClient();
client.setEndpoint(request.getSqsEndpoint());
try {
String queueUrl = client.createQueue(request.getQueueName()).getQueueUrl();
client.deleteMessage(queueUrl, message.getReceiptHandle());
} catch (Exception e) {
final String msg = "can not delete message. [" + request + "]";
throw new RuntimeException(msg, e);
} finally {
client.shutdown();
}
}
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:15,代码来源:ImageStateCheckAndPargeFunction.java
示例3: createQueueMessage
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入方法依赖的package包/类
SendMessageResult createQueueMessage(InstanceRequest instanceRequest, Context context) {
LambdaLogger logger = context.getLogger();
final String queueName = instanceRequest.getQueueName();
final String sqsEndpoint = instanceRequest.getSqsEndpoint();
if (queueName == null || sqsEndpoint == null) {
logger.log("skip create queue. instanceRequest[" + instanceRequest + "]");
return null;
}
AmazonSQSAsync client = createSQSClient();
client.setEndpoint(sqsEndpoint);
try {
CreateQueueRequest req = new CreateQueueRequest(queueName);
String queueUrl = client.createQueue(req).getQueueUrl();
instanceRequest.setSendMessageTimeMillis(System.currentTimeMillis());
SendMessageRequest sendMessage = new SendMessageRequest();
sendMessage.setQueueUrl(queueUrl);
ObjectMapper om = new ObjectMapper();
sendMessage.setMessageBody(om.writeValueAsString(instanceRequest));
Future<SendMessageResult> result = client.sendMessageAsync(sendMessage);
while (!result.isDone()) {
Thread.sleep(100);
}
return result.get();
} catch (Exception e) {
throw new RuntimeException("unexpected error occured in the create queue request.", e);
} finally {
client.shutdown();
}
}
示例4: deleteQueueMessage
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入方法依赖的package包/类
protected void deleteQueueMessage(Message message, InstanceCheckStateRequest checkInstanceStateRequest,
Context context) {
AmazonSQSAsync client = createSQSClient();
client.setEndpoint(checkInstanceStateRequest.getSqsEndpoint());
try {
String queueUrl = client.createQueue(checkInstanceStateRequest.getQueueName()).getQueueUrl();
client.deleteMessage(queueUrl, message.getReceiptHandle());
} catch (Exception e) {
final String msg = "can not delete message. checkInstanceStateRequest[" + checkInstanceStateRequest + "]";
throw new RuntimeException(msg, e);
} finally {
client.shutdown();
}
}
示例5: checkInstanceState
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入方法依赖的package包/类
public void checkInstanceState(InstanceCheckStateRequest checkInstanceStateRequest, Context context) {
LambdaLogger logger = context.getLogger();
final String queueName = checkInstanceStateRequest.getQueueName();
final String sqsEndpoint = checkInstanceStateRequest.getSqsEndpoint();
// illegal parameter
if (queueName == null || sqsEndpoint == null) {
logger.log("[ERROR][checkInstanceStatus][stopped]QueueName or SQSEndpoint is not found Parameter. ");
throw new IllegalArgumentException("QueueName or SQSEndpoint is not found Parameter. "
+ "CheckInstanceStateRequest[" + checkInstanceStateRequest + "]");
}
// Only the specified number, reliably acquired
int numberOfMessages = checkInstanceStateRequest.getNumberOfMessages();
for (int i = 0; i < numberOfMessages; i++) {
AmazonSQSAsync client = createSQSClient();
client.setEndpoint(sqsEndpoint);
try {
String queueUrl = client.createQueue(queueName).getQueueUrl();
ReceiveMessageRequest req = new ReceiveMessageRequest(queueUrl).withVisibilityTimeout(5)
.withMaxNumberOfMessages(checkInstanceStateRequest.getNumberOfMessages());
Future<ReceiveMessageResult> result = client.receiveMessageAsync(req);
while (!result.isDone()) {
Thread.sleep(100);
}
result.get().getMessages().stream()
.forEach(s -> checkInstanceState(s, "stopped", checkInstanceStateRequest, context));
} catch (Exception e) {
logger.log("[ERROR][checkInstanceStatus][stopped]message[" + e.getMessage() + "] stackTrace["
+ getStackTrace(e) + "] CheckInstanceStateRequest[" + checkInstanceStateRequest + "]");
} finally {
client.shutdown();
}
}
}
示例6: checkInstanceState
import com.amazonaws.services.sqs.AmazonSQSAsync; //导入方法依赖的package包/类
public void checkInstanceState(InstanceCheckStateRequest checkInstanceStateRequest, Context context) {
LambdaLogger logger = context.getLogger();
final String queueName = checkInstanceStateRequest.getQueueName();
final String sqsEndpoint = checkInstanceStateRequest.getSqsEndpoint();
// illegal parameter
if (queueName == null || sqsEndpoint == null) {
logger.log("[ERROR][checkInstanceStatus][running]QueueName or SQSEndpoint is not found Parameter. ");
throw new IllegalArgumentException("QueueName or SQSEndpoint is not found Parameter. "
+ "CheckInstanceStateRequest[" + checkInstanceStateRequest + "]");
}
// Only the specified number, reliably acquired
int numberOfMessages = checkInstanceStateRequest.getNumberOfMessages();
for (int i = 0; i < numberOfMessages; i++) {
AmazonSQSAsync client = createSQSClient();
client.setEndpoint(sqsEndpoint);
try {
String queueUrl = client.createQueue(queueName).getQueueUrl();
ReceiveMessageRequest req = new ReceiveMessageRequest(queueUrl).withVisibilityTimeout(5)
.withMaxNumberOfMessages(checkInstanceStateRequest.getNumberOfMessages());
Future<ReceiveMessageResult> result = client.receiveMessageAsync(req);
while (!result.isDone()) {
Thread.sleep(100);
}
result.get().getMessages().stream()
.forEach(s -> checkInstanceState(s, "running", checkInstanceStateRequest, context));
} catch (Exception e) {
logger.log("[ERROR][checkInstanceStatus][running]message[" + e.getMessage() + "] stackTrace["
+ getStackTrace(e) + "] CheckInstanceStateRequest[" + checkInstanceStateRequest + "]");
} finally {
client.shutdown();
}
}
}