当前位置: 首页>>代码示例>>Java>>正文


Java MessageAttributeValue类代码示例

本文整理汇总了Java中com.amazonaws.services.sqs.model.MessageAttributeValue的典型用法代码示例。如果您正苦于以下问题:Java MessageAttributeValue类的具体用法?Java MessageAttributeValue怎么用?Java MessageAttributeValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MessageAttributeValue类属于com.amazonaws.services.sqs.model包,在下文中一共展示了MessageAttributeValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createExchange

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
private Exchange createExchange(ExchangePattern pattern, com.amazonaws.services.sqs.model.Message msg) {
    Exchange exchange = super.createExchange(pattern);
    Message message = exchange.getIn();
    message.setBody(msg.getBody());
    message.setHeaders(new HashMap<String, Object>(msg.getAttributes()));
    message.setHeader(SqsConstants.MESSAGE_ID, msg.getMessageId());
    message.setHeader(SqsConstants.MD5_OF_BODY, msg.getMD5OfBody());
    message.setHeader(SqsConstants.RECEIPT_HANDLE, msg.getReceiptHandle());
    message.setHeader(SqsConstants.ATTRIBUTES, msg.getAttributes());
    message.setHeader(SqsConstants.MESSAGE_ATTRIBUTES, msg.getMessageAttributes());
    
    //Need to apply the SqsHeaderFilterStrategy this time
    HeaderFilterStrategy headerFilterStrategy = getHeaderFilterStrategy();
    //add all sqs message attributes as camel message headers so that knowledge of 
    //the Sqs class MessageAttributeValue will not leak to the client
    for (Entry<String, MessageAttributeValue> entry : msg.getMessageAttributes().entrySet()) {
        String header = entry.getKey();
        Object value = translateValue(entry.getValue());
        if (!headerFilterStrategy.applyFilterToExternalHeaders(header, value, exchange)) {
            message.setHeader(header, value);
        }
    }
    return exchange;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:SqsEndpoint.java

示例2: sendMessage

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
@Override
public SendMessageResult sendMessage(AwsParamsDto awsParamsDto, String queueName, String messageText, List<MessageHeader> messageHeaders)
{
    Map<String, MessageAttributeValue> messageAttributes = null;

    if (CollectionUtils.isNotEmpty(messageHeaders))
    {
        messageAttributes = new HashMap<>();

        for (MessageHeader messageHeader : messageHeaders)
        {
            messageAttributes.put(messageHeader.getKey(), new MessageAttributeValue().withDataType("String").withStringValue(messageHeader.getValue()));
        }
    }

    return sqsOperations.sendMessage(queueName, messageText, messageAttributes, awsClientFactory.getAmazonSQSClient(awsParamsDto));
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:18,代码来源:SqsDaoImpl.java

示例3: sendMessage

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
@Override
public SendMessageResult sendMessage(String queueName, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSQS amazonSQS)
{
    // Throw a throttling exception for a specific queue name for testing purposes.
    if (queueName.equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION))
    {
        AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception");
        throttlingException.setErrorCode("ThrottlingException");
        throw throttlingException;
    }

    // Throw an illegal state exception for a specific queue name for testing purposes.
    if (queueName.equals(MOCK_SQS_QUEUE_NOT_FOUND_NAME))
    {
        throw new IllegalStateException(String.format("AWS SQS queue with \"%s\" name not found.", queueName));
    }

    // Nothing else to do in the normal case since our unit tests aren't reading messages once they have been published.
    return new SendMessageResult().withMessageId(AbstractDaoTest.MESSAGE_ID);
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:21,代码来源:MockSqsOperationsImpl.java

示例4: shouldSendMessageWithCorrectAttributes

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
@Test
public void shouldSendMessageWithCorrectAttributes() {
    //GIVEN
    String body = "Sample text message";
    Map<String, MessageAttributeValue> attributes = new HashMap<>();
    attributes.put("attribute1", new MessageAttributeValue()
            .withDataType("String")
            .withStringValue("value1"));
    attributes.put("attribute2", new MessageAttributeValue()
            .withDataType("Number")
            .withStringValue("230.000000000000000001"));

    //WHEN
    sender.send(body, attributes);

    //THEN
    SendMessageRequest expected = new SendMessageRequest();
    expected.withQueueUrl(queueUrl)
            .withMessageBody(body)
            .withMessageAttributes(attributes);
    verify(sqs).sendMessage(expected);
}
 
开发者ID:sjarrin,项目名称:dropwizard-sqs-bundle,代码行数:23,代码来源:SqsSenderTest.java

示例5: shouldSendObjectMessageWithCorrectAttributes

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
@Test
public void shouldSendObjectMessageWithCorrectAttributes() throws JsonProcessingException {
    //GIVEN
    DummyObject bodyObject = new DummyObject();
    Map<String, MessageAttributeValue> attributes = new HashMap<>();
    attributes.put("attribute1", new MessageAttributeValue()
            .withDataType("String")
            .withStringValue("value1"));
    attributes.put("attribute2", new MessageAttributeValue()
            .withDataType("Number")
            .withStringValue("230.000000000000000001"));

    //WHEN
    sender.send(bodyObject, attributes);

    //THEN
    SendMessageRequest expected = new SendMessageRequest();
    expected.withQueueUrl(queueUrl)
            .withMessageBody(objectMapper.writeValueAsString(bodyObject))
            .withMessageAttributes(attributes);
    verify(sqs).sendMessage(expected);
}
 
开发者ID:sjarrin,项目名称:dropwizard-sqs-bundle,代码行数:23,代码来源:SqsSenderTest.java

示例6: getMsgAttributesSize

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
private int getMsgAttributesSize(Map<String, MessageAttributeValue> msgAttributes) {
	int totalMsgAttributesSize = 0;
	for (Entry<String, MessageAttributeValue> entry : msgAttributes.entrySet()) {
		totalMsgAttributesSize += getStringSizeInBytes(entry.getKey());

		MessageAttributeValue entryVal = entry.getValue();
		if (entryVal.getDataType() != null) {
			totalMsgAttributesSize += getStringSizeInBytes(entryVal.getDataType());
		}

		String stringVal = entryVal.getStringValue();
		if (stringVal != null) {
			totalMsgAttributesSize += getStringSizeInBytes(entryVal.getStringValue());
		}

		ByteBuffer binaryVal = entryVal.getBinaryValue();
		if (binaryVal != null) {
			totalMsgAttributesSize += binaryVal.array().length;
		}
	}
	return totalMsgAttributesSize;
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-extended-client-lib,代码行数:23,代码来源:AmazonSQSExtendedClient.java

示例7: createBatchesForQueues

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
/***
 * Categorize the messages into batches per queue
 * @param messages
 * @return messageBatches - belonging to one or more queues
 */
private Map<String, List<SendMessageBatchRequestEntry>> createBatchesForQueues(final List<Message> messages) {
	
	final Map<String, List<SendMessageBatchRequestEntry>> messageBatches = new HashMap<String, List<SendMessageBatchRequestEntry>>();

	for(Message message : messages){
		final Map<String, MessageAttributeValue> attributes = this.toMessageAttrs(message);
		
		final SendMessageBatchRequestEntry entry = new SendMessageBatchRequestEntry() 
		.withId(message.getId())
		.withMessageAttributes(attributes)
		.withMessageBody(message.getBody());

		if(!messageBatches.containsKey(message.getQueue())){
			messageBatches.put(message.getQueue(), new ArrayList<SendMessageBatchRequestEntry>());
		}
		messageBatches.get(message.getQueue()).add(entry);
	}
	return messageBatches;
}
 
开发者ID:shagwood,项目名称:micro-genie,代码行数:25,代码来源:SqsProducer.java

示例8: prepareSendMessageRequest

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
private SendMessageRequest prepareSendMessageRequest(Message<?> message) {
    SendMessageRequest sendMessageRequest = new SendMessageRequest(this.queueUrl, String.valueOf(message.getPayload()));

    if (message.getHeaders().containsKey(SqsMessageHeaders.SQS_GROUP_ID_HEADER)) {
        sendMessageRequest.setMessageGroupId(message.getHeaders().get(SqsMessageHeaders.SQS_GROUP_ID_HEADER, String.class));
    }

    if (message.getHeaders().containsKey(SqsMessageHeaders.SQS_DEDUPLICATION_ID_HEADER)) {
        sendMessageRequest.setMessageDeduplicationId(message.getHeaders().get(SqsMessageHeaders.SQS_DEDUPLICATION_ID_HEADER, String.class));
    }

    if (message.getHeaders().containsKey(SqsMessageHeaders.SQS_DELAY_HEADER)) {
        sendMessageRequest.setDelaySeconds(message.getHeaders().get(SqsMessageHeaders.SQS_DELAY_HEADER, Integer.class));
    }

    Map<String, MessageAttributeValue> messageAttributes = getMessageAttributes(message);
    if (!messageAttributes.isEmpty()) {
        sendMessageRequest.withMessageAttributes(messageAttributes);
    }

    return sendMessageRequest;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:23,代码来源:QueueMessageChannel.java

示例9: getMessageAttributesAsMessageHeaders

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
private static Map<String, Object> getMessageAttributesAsMessageHeaders(com.amazonaws.services.sqs.model.Message message) {
    Map<String, Object> messageHeaders = new HashMap<>();
    for (Map.Entry<String, MessageAttributeValue> messageAttribute : message.getMessageAttributes().entrySet()) {
        if (MessageHeaders.CONTENT_TYPE.equals(messageAttribute.getKey())) {
            messageHeaders.put(MessageHeaders.CONTENT_TYPE, MimeType.valueOf(messageAttribute.getValue().getStringValue()));
        } else if (MessageHeaders.ID.equals(messageAttribute.getKey())) {
            messageHeaders.put(MessageHeaders.ID, UUID.fromString(messageAttribute.getValue().getStringValue()));
        } else if (MessageAttributeDataTypes.STRING.equals(messageAttribute.getValue().getDataType())) {
            messageHeaders.put(messageAttribute.getKey(), messageAttribute.getValue().getStringValue());
        } else if (messageAttribute.getValue().getDataType().startsWith(MessageAttributeDataTypes.NUMBER)) {
            Object numberValue = getNumberValue(messageAttribute.getValue());
            if (numberValue != null) {
                messageHeaders.put(messageAttribute.getKey(), numberValue);
            }
        } else if (MessageAttributeDataTypes.BINARY.equals(messageAttribute.getValue().getDataType())) {
            messageHeaders.put(messageAttribute.getKey(), messageAttribute.getValue().getBinaryValue());
        }
    }

    return messageHeaders;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:22,代码来源:QueueMessageUtils.java

示例10: receiveMessage_withMimeTypeMessageAttribute_shouldCopyToHeaders

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
@Test
public void receiveMessage_withMimeTypeMessageAttribute_shouldCopyToHeaders() throws Exception {
    // Arrange
    AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
    MimeType mimeType = new MimeType("test", "plain", Charset.forName("UTF-8"));
    when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue").
            withWaitTimeSeconds(0).
            withMaxNumberOfMessages(1).
            withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES).
            withMessageAttributeNames("All"))).
            thenReturn(new ReceiveMessageResult().withMessages(new com.amazonaws.services.sqs.model.Message().withBody("Hello").
                    withMessageAttributes(Collections.singletonMap(MessageHeaders.CONTENT_TYPE,
                            new MessageAttributeValue().withDataType(MessageAttributeDataTypes.STRING).withStringValue(mimeType.toString())))));

    PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");

    // Act
    Message<?> receivedMessage = messageChannel.receive();

    // Assert
    assertEquals(mimeType, receivedMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:23,代码来源:QueueMessageChannelTest.java

示例11: receiveMessage_withStringMessageHeader_shouldBeReceivedAsQueueMessageAttribute

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
@Test
public void receiveMessage_withStringMessageHeader_shouldBeReceivedAsQueueMessageAttribute() throws Exception {
    // Arrange
    AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
    String headerValue = "Header value";
    String headerName = "MyHeader";
    when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue").
            withWaitTimeSeconds(0).
            withMaxNumberOfMessages(1).
            withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES).
            withMessageAttributeNames("All"))).
            thenReturn(new ReceiveMessageResult().withMessages(new com.amazonaws.services.sqs.model.Message().withBody("Hello").
                    withMessageAttributes(Collections.singletonMap(headerName,
                            new MessageAttributeValue().withDataType(MessageAttributeDataTypes.STRING).withStringValue(headerValue)))));

    PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");

    // Act
    Message<?> receivedMessage = messageChannel.receive();

    // Assert
    assertEquals(headerValue, receivedMessage.getHeaders().get(headerName));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:24,代码来源:QueueMessageChannelTest.java

示例12: receiveMessage_withIncompatibleNumericMessageHeader_shouldThrowAnException

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
@Test
public void receiveMessage_withIncompatibleNumericMessageHeader_shouldThrowAnException() throws Exception {
    // Arrange
    AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
    this.expectedException.expect(IllegalArgumentException.class);
    this.expectedException.expectMessage("Cannot convert String [17] to target class [java.util.concurrent.atomic.AtomicInteger]");

    HashMap<String, MessageAttributeValue> messageAttributes = new HashMap<>();
    AtomicInteger atomicInteger = new AtomicInteger(17);
    messageAttributes.put("atomicInteger", new MessageAttributeValue().withDataType(MessageAttributeDataTypes.NUMBER + ".java.util.concurrent.atomic.AtomicInteger").withStringValue(String.valueOf(atomicInteger)));

    when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue").
            withWaitTimeSeconds(0).
            withMaxNumberOfMessages(1).
            withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES).
            withMessageAttributeNames("All"))).
            thenReturn(new ReceiveMessageResult().withMessages(new com.amazonaws.services.sqs.model.Message().withBody("Hello").
                    withMessageAttributes(messageAttributes)));

    PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");

    // Act
    messageChannel.receive();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:25,代码来源:QueueMessageChannelTest.java

示例13: receiveMessage_withMissingNumericMessageHeaderTargetClass_shouldThrowAnException

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
@Test
public void receiveMessage_withMissingNumericMessageHeaderTargetClass_shouldThrowAnException() throws Exception {
    // Arrange
    AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
    this.expectedException.expect(MessagingException.class);
    this.expectedException.expectMessage("Message attribute with value '12' and data type 'Number.class.not.Found' could not be converted" +
            " into a Number because target class was not found.");

    HashMap<String, MessageAttributeValue> messageAttributes = new HashMap<>();
    messageAttributes.put("classNotFound", new MessageAttributeValue().withDataType(MessageAttributeDataTypes.NUMBER + ".class.not.Found").withStringValue("12"));

    when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue").
            withWaitTimeSeconds(0).
            withMaxNumberOfMessages(1).
            withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES).
            withMessageAttributeNames("All"))).
            thenReturn(new ReceiveMessageResult().withMessages(new com.amazonaws.services.sqs.model.Message().withBody("Hello").
                    withMessageAttributes(messageAttributes)));

    PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");

    // Act
    messageChannel.receive();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:25,代码来源:QueueMessageChannelTest.java

示例14: receiveMessage_withBinaryMessageHeader_shouldBeReceivedAsByteBufferMessageAttribute

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
@Test
public void receiveMessage_withBinaryMessageHeader_shouldBeReceivedAsByteBufferMessageAttribute() throws Exception {
    // Arrange
    AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
    ByteBuffer headerValue = ByteBuffer.wrap("My binary data!".getBytes());
    String headerName = "MyHeader";
    when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue").
            withWaitTimeSeconds(0).
            withMaxNumberOfMessages(1).
            withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES).
            withMessageAttributeNames("All"))).
            thenReturn(new ReceiveMessageResult().withMessages(new com.amazonaws.services.sqs.model.Message().withBody("Hello").
                    withMessageAttributes(Collections.singletonMap(headerName,
                            new MessageAttributeValue().withDataType(MessageAttributeDataTypes.BINARY).withBinaryValue(headerValue)))));

    PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");

    // Act
    Message<?> receivedMessage = messageChannel.receive();

    // Assert
    assertEquals(headerValue, receivedMessage.getHeaders().get(headerName));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:24,代码来源:QueueMessageChannelTest.java

示例15: receiveMessage_withIdOfTypeString_IdShouldBeConvertedToUuid

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入依赖的package包/类
@Test
public void receiveMessage_withIdOfTypeString_IdShouldBeConvertedToUuid() throws Exception {
    // Arrange
    AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class);
    UUID uuid = UUID.randomUUID();
    when(amazonSqs.receiveMessage(new ReceiveMessageRequest("http://testQueue").
            withWaitTimeSeconds(0).
            withMaxNumberOfMessages(1).
            withAttributeNames(QueueMessageChannel.ATTRIBUTE_NAMES).
            withMessageAttributeNames("All"))).
            thenReturn(new ReceiveMessageResult().withMessages(new com.amazonaws.services.sqs.model.Message().withBody("Hello").
                    withMessageAttributes(Collections.singletonMap(MessageHeaders.ID,
                            new MessageAttributeValue().withDataType(MessageAttributeDataTypes.STRING).withStringValue(uuid.toString())))));

    PollableChannel messageChannel = new QueueMessageChannel(amazonSqs, "http://testQueue");

    // Act
    Message<?> receivedMessage = messageChannel.receive();

    // Assert
    Object idMessageHeader = receivedMessage.getHeaders().get(MessageHeaders.ID);
    assertTrue(UUID.class.isInstance(idMessageHeader));
    assertEquals(uuid, idMessageHeader);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:25,代码来源:QueueMessageChannelTest.java


注:本文中的com.amazonaws.services.sqs.model.MessageAttributeValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。