@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetQueueUrlResult == false) return false; GetQueueUrlResult other = (GetQueueUrlResult) obj; if (other.getQueueUrl() == null ^ this.getQueueUrl() == null) return false; if (other.getQueueUrl() != null && other.getQueueUrl().equals(this.getQueueUrl()) == false) return false; return true; }
public GetQueueUrlResult unmarshall(StaxUnmarshallerContext context) throws Exception { GetQueueUrlResult getQueueUrlResult = new GetQueueUrlResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return getQueueUrlResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("QueueUrl", targetDepth)) { getQueueUrlResult.setQueueUrl(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return getQueueUrlResult; } } } }
@Bean public AmazonSQSAsync amazonSqs() { AmazonSQSAsync sqs = mock(AmazonSQSAsync.class); given(sqs.getQueueUrl(new GetQueueUrlRequest("testQueue"))) .willReturn(new GetQueueUrlResult().withQueueUrl("http://testQueue.amazonaws.com")); given(sqs.receiveMessage(new ReceiveMessageRequest("http://testQueue.amazonaws.com") .withAttributeNames("All") .withMessageAttributeNames("All") .withMaxNumberOfMessages(10) .withWaitTimeSeconds(20))) .willReturn(new ReceiveMessageResult() .withMessages(new Message().withBody("messageContent"), new Message().withBody("messageContent2"))) .willReturn(new ReceiveMessageResult()); given(sqs.getQueueAttributes(any(GetQueueAttributesRequest.class))) .willReturn(new GetQueueAttributesResult()); return sqs; }
/** * <p> * The URL of the queue. * </p> * * @param queueUrl * The URL of the queue. * @return Returns a reference to this object so that method calls can be chained together. */ public GetQueueUrlResult withQueueUrl(String queueUrl) { setQueueUrl(queueUrl); return this; }
/** * <p> * The URL of the queue. * </p> * * @param queueUrl * The URL of the queue. * @return Returns a reference to this object so that method calls can be chained together. */ public GetQueueUrlResult withQueueUrl(String queueUrl) { setQueueUrl(queueUrl); return this; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getQueueUrl() == null) ? 0 : getQueueUrl().hashCode()); return hashCode; }
public GetQueueUrlResult unmarshall(StaxUnmarshallerContext context) throws Exception { GetQueueUrlResult getQueueUrlResult = new GetQueueUrlResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) break; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("QueueUrl", targetDepth)) { getQueueUrlResult.setQueueUrl(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return getQueueUrlResult; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getQueueUrl() != null) sb.append("QueueUrl: ").append(getQueueUrl()); sb.append("}"); return sb.toString(); }
public GetQueueUrlResult unmarshall(StaxUnmarshallerContext context) throws Exception { GetQueueUrlResult getQueueUrlResult = new GetQueueUrlResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return getQueueUrlResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("QueueUrl", targetDepth)) { getQueueUrlResult.setQueueUrl(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return getQueueUrlResult; } } } }
public static String getQueueUrlByName( final AmazonSQSClient sqs, final String queueName ) { try { GetQueueUrlResult result = sqs.getQueueUrl( queueName ); return result.getQueueUrl(); } catch ( QueueDoesNotExistException e ) { //no op, return null logger.error( "Queue {} does not exist", queueName ); return null; } catch ( Exception e ) { logger.error( "failed to get queue from service", e ); throw e; } } }
public GetQueueUrlResult unmarshall(StaxUnmarshallerContext context) throws Exception { GetQueueUrlResult getQueueUrlResult = new GetQueueUrlResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) break; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("QueueUrl", targetDepth)) { getQueueUrlResult.setQueueUrl(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return getQueueUrlResult; }
/** create a task statistics store for the given queue name */ public SQSTaskStatisticsStore(String queueName) { Region current = Regions.getCurrentRegion(); if (current != null) { LOG.info("Assuming statistics queue is in region {}", current); sqs.setEndpoint("sqs." + current.toString() + ".amazonaws.com"); } try { queueUrl = sqs.getQueueUrl(queueName).getQueueUrl(); } catch (Exception e) { LOG.error("Unable to initialize statistics store", e); } LOG.info("Sending statistics to SQS queue {}", queueName); }
@Bean public AmazonSQSAsync amazonSqs() { AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); willAnswer(invocation -> { GetQueueUrlRequest getQueueUrlRequest = (GetQueueUrlRequest) invocation.getArguments()[0]; GetQueueUrlResult queueUrl = new GetQueueUrlResult(); queueUrl.setQueueUrl("http://queue-url.com/" + getQueueUrlRequest.getQueueName()); return queueUrl; }) .given(amazonSqs) .getQueueUrl(any(GetQueueUrlRequest.class)); willAnswer(invocation -> { CreateQueueRequest createQueueRequest = (CreateQueueRequest) invocation.getArguments()[0]; CreateQueueResult queueUrl = new CreateQueueResult(); queueUrl.setQueueUrl("http://queue-url.com/" + createQueueRequest.getQueueName()); return queueUrl; }) .given(amazonSqs) .createQueue(any(CreateQueueRequest.class)); return amazonSqs; }
@Override public LegacyQueue load(String queueName ) throws Exception { LegacyQueue queue = null; try { GetQueueUrlResult result = sqs.getQueueUrl( queueName ); queue = new LegacyQueue( result.getQueueUrl() ); } catch ( QueueDoesNotExistException queueDoesNotExistException ) { if (queueName.endsWith(DEAD_LETTER_QUEUE_SUFFIX)) { // don't auto-create dead letter queues logger.error("failed to get dead letter queue from service, won't create", queueDoesNotExistException); throw queueDoesNotExistException; } logger.error( "Queue {} does not exist, will create", queueName ); } catch ( Exception e ) { logger.error( "failed to get queue from service", e ); throw e; } if ( queue == null ) { String url = AmazonNotificationUtils.createQueue( sqs, queueName, fig ); queue = new LegacyQueue( url ); } setupTopics( queueName ); return queue; } } );
public static String getQueueArnByName( final AmazonSQSClient sqs, final String queueName ) throws Exception { String queueUrl = null; try { GetQueueUrlResult result = sqs.getQueueUrl( queueName ); queueUrl = result.getQueueUrl(); } catch ( QueueDoesNotExistException queueDoesNotExistException ) { //no op, swallow logger.warn( "Queue {} does not exist", queueName ); return null; } catch ( Exception e ) { logger.error( "Failed to get URL for Queue [{}] from SQS", queueName, e ); throw e; } if ( queueUrl != null ) { try { GetQueueAttributesRequest queueAttributesRequest = new GetQueueAttributesRequest( queueUrl ).withAttributeNames( "All" ); GetQueueAttributesResult queueAttributesResult = sqs.getQueueAttributes( queueAttributesRequest ); Map<String, String> sqsAttributeMap = queueAttributesResult.getAttributes(); return sqsAttributeMap.get( "QueueArn" ); } catch ( Exception e ) { logger.error( "Failed to get queue URL from service", e ); throw e; } } return null; }
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); } }
String queue_url = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getQueueUrl() == null) ? 0 : getQueueUrl().hashCode()); return hashCode; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetQueueUrlResult == false) return false; GetQueueUrlResult other = (GetQueueUrlResult) obj; if (other.getQueueUrl() == null ^ this.getQueueUrl() == null) return false; if (other.getQueueUrl() != null && other.getQueueUrl().equals(this.getQueueUrl()) == false) return false; return true; } }