@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAttributes() == null) ? 0 : getAttributes().hashCode()); return hashCode; }
public GetQueueAttributesResult unmarshall(StaxUnmarshallerContext context) throws Exception { GetQueueAttributesResult getQueueAttributesResult = new GetQueueAttributesResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return getQueueAttributesResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Attribute", targetDepth)) { Entry<String, String> entry = AttributesMapEntryUnmarshaller.getInstance().unmarshall(context); getQueueAttributesResult.addAttributesEntry(entry.getKey(), entry.getValue()); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return getQueueAttributesResult; } } } }
@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; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetQueueAttributesResult == false) return false; GetQueueAttributesResult other = (GetQueueAttributesResult) obj; if (other.getAttributes() == null ^ this.getAttributes() == null) return false; if (other.getAttributes() != null && other.getAttributes().equals(this.getAttributes()) == false) return false; return true; }
public GetQueueAttributesResult unmarshall(StaxUnmarshallerContext context) throws Exception { GetQueueAttributesResult getQueueAttributesResult = new GetQueueAttributesResult(); 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("Attribute", targetDepth)) { Entry<String, String> entry = AttributesMapEntryUnmarshaller.getInstance() .unmarshall(context); getQueueAttributesResult.addAttributesEntry(entry.getKey(), entry.getValue()); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return getQueueAttributesResult; }
/** * 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 (getAttributes() != null) sb.append("Attributes: ").append(getAttributes()); sb.append("}"); return sb.toString(); }
public GetQueueAttributesResult unmarshall(StaxUnmarshallerContext context) throws Exception { GetQueueAttributesResult getQueueAttributesResult = new GetQueueAttributesResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return getQueueAttributesResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Attribute", targetDepth)) { Entry<String, String> entry = AttributesMapEntryUnmarshaller.getInstance().unmarshall(context); getQueueAttributesResult.addAttributesEntry(entry.getKey(), entry.getValue()); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return getQueueAttributesResult; } } } }
@Override public long size() { GetQueueAttributesResult attributes = client.getQueueAttributes(queueURL, Collections.singletonList("ApproximateNumberOfMessages")); String sizeAsStr = attributes.getAttributes().get("ApproximateNumberOfMessages"); try { return Long.parseLong(sizeAsStr); } catch(Exception e) { return -1; } }
public GetQueueAttributesResult unmarshall(StaxUnmarshallerContext context) throws Exception { GetQueueAttributesResult getQueueAttributesResult = new GetQueueAttributesResult(); 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("Attribute", targetDepth)) { Entry<String, String> entry = AttributesMapEntryUnmarshaller.getInstance() .unmarshall(context); getQueueAttributesResult.addAttributesEntry(entry.getKey(), entry.getValue()); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return getQueueAttributesResult; }
private String getQueueARN() { GetQueueAttributesResult response = client.getQueueAttributes(queueURL, Collections.singletonList("QueueArn")); return response.getAttributes().get("QueueArn"); }
@Override public long getQueueDepth() { String key = "ApproximateNumberOfMessages"; try { GetQueueAttributesResult result = sqs.getQueueAttributes( getReadQueue().getUrl(), Collections.singletonList( key ) ); String depthString = result.getAttributes().get( key ); return depthString != null ? Long.parseLong( depthString ) : 0; } catch ( Exception e ) { logger.error( "Exception getting queue depth", e ); return -1; } }
public static String getQueueArnByUrl( final AmazonSQSClient sqs, final String queueUrl ) throws Exception { 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; } }
.withAttributeNames("VisibilityTimeout"); ResultConverter.appendUserAgent(request, AmazonSQSBufferedAsyncClient.USER_AGENT); long visibilityTimeoutSeconds = Long.parseLong(sqsClient.getQueueAttributes(request).getAttributes() .get("VisibilityTimeout")); visibilityTimeoutNanos = TimeUnit.NANOSECONDS.convert(visibilityTimeoutSeconds, TimeUnit.SECONDS);
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; }
.withAttributeNames("QueueArn")); String dl_queue_arn = queue_attrs.getAttributes().get("QueueArn");
new GetQueueAttributesRequest( queueUrl ).withAttributeNames( sqsAttrNames ); GetQueueAttributesResult queueAttributesResult = sqs.getQueueAttributes( getQueueAttributesRequest ); Map<String, String> sqsAttributeMap = queueAttributesResult.getAttributes(); String queueARN = sqsAttributeMap.get(QueueAttributeName.QueueArn.toString()); String policyJson = sqsAttributeMap.get(QueueAttributeName.Policy.toString());
List<String> sqsAttrNames = Arrays.asList(QueueAttributeName.QueueArn.toString(), QueueAttributeName.Policy.toString()); Map<String, String> sqsAttrs = sqs.getQueueAttributes(sqsQueueUrl, sqsAttrNames).getAttributes(); String sqsQueueArn = sqsAttrs.get(QueueAttributeName.QueueArn.toString());
private void setupQueueAndTopic() { String randomSeed = UUID.randomUUID().toString(); String queueName = "glacier-archive-transfer-" + randomSeed; String topicName = "glacier-archive-transfer-" + randomSeed; queueUrl = sqs.createQueue(new CreateQueueRequest(queueName)).getQueueUrl(); topicArn = sns.createTopic(new CreateTopicRequest(topicName)).getTopicArn(); String queueARN = sqs.getQueueAttributes(new GetQueueAttributesRequest(queueUrl).withAttributeNames("QueueArn")).getAttributes().get("QueueArn"); Policy sqsPolicy = new Policy().withStatements( new Statement(Effect.Allow) .withPrincipals(Principal.AllUsers) .withActions(SQSActions.SendMessage) .withResources(new Resource(queueARN)) .withConditions(ConditionFactory.newSourceArnCondition(topicArn))); sqs.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, newAttributes("Policy", sqsPolicy.toJson()))); sns.subscribe(new SubscribeRequest(topicArn, "sqs", queueARN)); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAttributes() == null) ? 0 : getAttributes().hashCode()); return hashCode; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetQueueAttributesResult == false) return false; GetQueueAttributesResult other = (GetQueueAttributesResult) obj; if (other.getAttributes() == null ^ this.getAttributes() == null) return false; if (other.getAttributes() != null && other.getAttributes().equals(this.getAttributes()) == false) return false; return true; } }