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


Java MessageAttributeValue.setDataType方法代码示例

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


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

示例1: storeMessageInS3

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
private SendMessageBatchRequestEntry storeMessageInS3(SendMessageBatchRequestEntry batchEntry) {

		checkMessageAttributes(batchEntry.getMessageAttributes());

		String s3Key = UUID.randomUUID().toString();

		// Read the content of the message from message body
		String messageContentStr = batchEntry.getMessageBody();

		Long messageContentSize = getStringSizeInBytes(messageContentStr);

		// Add a new message attribute as a flag
		MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
		messageAttributeValue.setDataType("Number");
		messageAttributeValue.setStringValue(messageContentSize.toString());
		batchEntry.addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, messageAttributeValue);

		// Store the message content in S3.
		storeTextInS3(s3Key, messageContentStr, messageContentSize);

		LOG.info("S3 object created, Bucket name: " + clientConfiguration.getS3BucketName() + ", Object key: " + s3Key
				+ ".");

		// Convert S3 pointer (bucket name, key, etc) to JSON string
		MessageS3Pointer s3Pointer = new MessageS3Pointer(clientConfiguration.getS3BucketName(), s3Key);
		String s3PointerStr = getJSONFromS3Pointer(s3Pointer);

		// Storing S3 pointer in the message body.
		batchEntry.setMessageBody(s3PointerStr);

		return batchEntry;
	}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-extended-client-lib,代码行数:33,代码来源:AmazonSQSExtendedClient.java

示例2: propertyToMessageAttribute

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Not verified on the client side, but SQS Attribute names must be valid
 * letter or digit on the basic multilingual plane in addition to allowing
 * '_', '-' and '.'. No component of an attribute name may be empty, thus an
 * attribute name may neither start nor end in '.'. And it may not contain
 * "..".
 */
Map<String, MessageAttributeValue> propertyToMessageAttribute(SQSMessage message)
        throws JMSException {
    Map<String, MessageAttributeValue> messageAttributes = new HashMap<String, MessageAttributeValue>();
    Enumeration<String> propertyNames = message.getPropertyNames();

    while (propertyNames.hasMoreElements()) {
        String propertyName = propertyNames.nextElement();

        // This is generated from SQS message attribute "ApproximateReceiveCount"
        if (propertyName.equals(SQSMessagingClientConstants.JMSX_DELIVERY_COUNT)) {
            continue;
        }

        // This property will be used as DeduplicationId argument of SendMessage call
        // On receive it is mapped back to this JMS property
        if (propertyName.equals(SQSMessagingClientConstants.JMS_SQS_DEDUPLICATION_ID)) {
            continue;
        }

        // the JMSXGroupID and JMSXGroupSeq are always stored as message
        // properties, so they are not lost between send and receive
        // even though SQS Classic does not respect those values when returning messages
        // and SQS FIFO has a different understanding of message groups

        JMSMessagePropertyValue propertyObject = message.getJMSMessagePropertyValue(propertyName);
        MessageAttributeValue messageAttributeValue = new MessageAttributeValue();

        messageAttributeValue.setDataType(propertyObject.getType());
        messageAttributeValue.setStringValue(propertyObject.getStringMessageAttributeValue());

        messageAttributes.put(propertyName, messageAttributeValue);
    }
    return messageAttributes;
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:42,代码来源:SQSMessageProducer.java

示例3: addStringAttribute

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Convenience method for adding a single string attribute.
 */
private void addStringAttribute(Map<String, MessageAttributeValue> messageAttributes,
                                String key, String value) {
    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setDataType(SQSMessagingClientConstants.STRING);
    messageAttributeValue.setStringValue(value);
    messageAttributes.put(key, messageAttributeValue);
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:11,代码来源:SQSMessageProducer.java

示例4: testPropertyToMessageAttributeWithEmpty

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Test propertyToMessageAttribute with empty messages of different type
 */
@Test
public void testPropertyToMessageAttributeWithEmpty() throws JMSException {

    /*
     * Test Empty text message default attribute
     */
    SQSMessage sqsText = new SQSTextMessage();
    Map<String, MessageAttributeValue> messageAttributeText = producer.propertyToMessageAttribute(sqsText);

    assertEquals(0, messageAttributeText.size());

    /*
     * Test Empty object message default attribute
     */
    SQSMessage sqsObject = new SQSObjectMessage();
    Map<String, MessageAttributeValue> messageAttributeObject = producer.propertyToMessageAttribute(sqsObject);

    assertEquals(0, messageAttributeObject.size());

    /*
     * Test Empty byte message default attribute
     */
    MessageAttributeValue messageAttributeValueByte = new MessageAttributeValue();
    messageAttributeValueByte.setDataType("String");
    messageAttributeValueByte.setStringValue("byte");

    SQSMessage sqsByte = new SQSBytesMessage();
    Map<String, MessageAttributeValue> messageAttributeByte = producer.propertyToMessageAttribute(sqsByte);

    assertEquals(0, messageAttributeObject.size());
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:35,代码来源:SQSMessageProducerTest.java

示例5: testSendInternalSQSTextMessageFromReceivedMessage

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Test sendInternal input with SQSTextMessage
 */
@Test
public void testSendInternalSQSTextMessageFromReceivedMessage() throws JMSException {

    /*
     * Set up non JMS sqs message
     */
    Map<String,MessageAttributeValue> mapMessageAttributes = new HashMap<String, MessageAttributeValue>();
    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setStringValue(SQSMessage.TEXT_MESSAGE_TYPE);
    messageAttributeValue.setDataType(SQSMessagingClientConstants.STRING);
    mapMessageAttributes.put(SQSMessage.JMS_SQS_MESSAGE_TYPE, messageAttributeValue);

    Map<String, String> mapAttributes = new HashMap<String, String>();
    mapAttributes.put(SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT, "1");

    com.amazonaws.services.sqs.model.Message message =
            new com.amazonaws.services.sqs.model.Message()
                        .withMessageAttributes(mapMessageAttributes)
                        .withAttributes(mapAttributes)
                        .withBody("MessageBody");

    SQSTextMessage msg = spy(new SQSTextMessage(acknowledger, QUEUE_URL, message));

    when(amazonSQSClient.sendMessage(any(SendMessageRequest.class)))
            .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID_1));

    producer.sendInternal(destination, msg);

    List<String> messagesBody = Arrays.asList("MessageBody");
    verify(amazonSQSClient).sendMessage(argThat(new sendMessageRequestMatcher(QUEUE_URL, messagesBody, mapMessageAttributes)));
    verify(msg).setJMSDestination(destination);
    verify(msg).setJMSMessageID("ID:" + MESSAGE_ID_1);
    verify(msg).setSQSMessageId(MESSAGE_ID_1);
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:38,代码来源:SQSMessageProducerTest.java

示例6: testSendInternalSQSByteMessageFromReceivedMessage

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Test sendInternal input with SQSByteMessage
 */
@Test
public void testSendInternalSQSByteMessageFromReceivedMessage() throws JMSException, IOException {
    
    /*
     * Set up non JMS sqs message
     */
    Map<String,MessageAttributeValue> mapMessageAttributes = new HashMap<String, MessageAttributeValue>();
    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setStringValue(SQSMessage.BYTE_MESSAGE_TYPE);
    messageAttributeValue.setDataType(SQSMessagingClientConstants.STRING);
    mapMessageAttributes.put(SQSMessage.JMS_SQS_MESSAGE_TYPE, messageAttributeValue);

    Map<String, String> mapAttributes = new HashMap<String, String>();
    mapAttributes.put(SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT, "1");

    byte[] byteArray = new byte[] { 1, 0, 'a', 65 };
    String messageBody = Base64.encodeAsString(byteArray);
    com.amazonaws.services.sqs.model.Message message =
            new com.amazonaws.services.sqs.model.Message()
                    .withMessageAttributes(mapMessageAttributes)
                    .withAttributes(mapAttributes)
                    .withBody(messageBody);

    SQSObjectMessage msg = spy(new SQSObjectMessage(acknowledger, QUEUE_URL, message));

    Map<String, MessageAttributeValue> messageAttributes = createMessageAttribute("object");

    when(amazonSQSClient.sendMessage(any(SendMessageRequest.class)))
            .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID_1))
            .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID_2));

    producer.sendInternal(destination, msg);

    verify(amazonSQSClient).sendMessage(argThat(new sendMessageRequestMatcher(QUEUE_URL, Arrays.asList(messageBody),
            messageAttributes)));
    verify(msg).setJMSDestination(destination);
    verify(msg).setJMSMessageID("ID:" + MESSAGE_ID_1);
    verify(msg).setSQSMessageId(MESSAGE_ID_1);
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:43,代码来源:SQSMessageProducerTest.java

示例7: createMessageAttribute

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
private Map<String, MessageAttributeValue> createMessageAttribute(String type) {
    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setDataType("String");
    messageAttributeValue.setStringValue(type);

    Map<String, MessageAttributeValue> messageAttributes = new HashMap<String, MessageAttributeValue>();
    messageAttributes.put(SQSMessage.JMS_SQS_MESSAGE_TYPE, messageAttributeValue);
    return messageAttributes;
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:10,代码来源:SQSMessageProducerTest.java

示例8: testSendInternalSQSTextMessageFromReceivedMessage

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Test sendInternal input with SQSTextMessage
 */
@Test
public void testSendInternalSQSTextMessageFromReceivedMessage() throws JMSException {

    /*
     * Set up non JMS sqs message
     */
    Map<String,MessageAttributeValue> mapMessageAttributes = new HashMap<String, MessageAttributeValue>();
    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setStringValue(SQSMessage.TEXT_MESSAGE_TYPE);
    messageAttributeValue.setDataType(SQSMessagingClientConstants.STRING);
    mapMessageAttributes.put(SQSMessage.JMS_SQS_MESSAGE_TYPE, messageAttributeValue);

    Map<String, String> mapAttributes = new HashMap<String, String>();
    mapAttributes.put(SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT, "1");
    mapAttributes.put(SQSMessagingClientConstants.MESSAGE_GROUP_ID, GROUP_ID);
    mapAttributes.put(SQSMessagingClientConstants.MESSAGE_DEDUPLICATION_ID, DEDUP_ID);
    mapAttributes.put(SQSMessagingClientConstants.SEQUENCE_NUMBER, SEQ_NUMBER);

    com.amazonaws.services.sqs.model.Message message =
            new com.amazonaws.services.sqs.model.Message()
                        .withMessageAttributes(mapMessageAttributes)
                        .withAttributes(mapAttributes)
                        .withBody("MessageBody");

    SQSTextMessage msg = spy(new SQSTextMessage(acknowledger, QUEUE_URL, message));

    when(amazonSQSClient.sendMessage(any(SendMessageRequest.class)))
            .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID).withSequenceNumber(SEQ_NUMBER_2));

    producer.sendInternal(destination, msg);

    verify(amazonSQSClient).sendMessage(argThat(new sendMessageRequestMatcher(QUEUE_URL, "MessageBody", SQSMessage.TEXT_MESSAGE_TYPE, GROUP_ID, DEDUP_ID)));
    verify(msg).setJMSDestination(destination);
    verify(msg).setJMSMessageID("ID:" + MESSAGE_ID);
    verify(msg).setSQSMessageId(MESSAGE_ID);
    verify(msg).setSequenceNumber(SEQ_NUMBER_2);
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:41,代码来源:SQSMessageProducerFifoTest.java

示例9: testSendInternalSQSByteMessageFromReceivedMessage

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Test sendInternal input with SQSByteMessage
 */
@Test
public void testSendInternalSQSByteMessageFromReceivedMessage() throws JMSException, IOException {
    
    /*
     * Set up non JMS sqs message
     */
    Map<String,MessageAttributeValue> mapMessageAttributes = new HashMap<String, MessageAttributeValue>();
    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setStringValue(SQSMessage.BYTE_MESSAGE_TYPE);
    messageAttributeValue.setDataType(SQSMessagingClientConstants.STRING);
    mapMessageAttributes.put(SQSMessage.JMS_SQS_MESSAGE_TYPE, messageAttributeValue);

    Map<String, String> mapAttributes = new HashMap<String, String>();
    mapAttributes.put(SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT, "1");
    mapAttributes.put(SQSMessagingClientConstants.MESSAGE_GROUP_ID, GROUP_ID);
    mapAttributes.put(SQSMessagingClientConstants.MESSAGE_DEDUPLICATION_ID, DEDUP_ID);
    mapAttributes.put(SQSMessagingClientConstants.SEQUENCE_NUMBER, SEQ_NUMBER);

    byte[] byteArray = new byte[] { 1, 0, 'a', 65 };
    String messageBody = Base64.encodeAsString(byteArray);
    com.amazonaws.services.sqs.model.Message message =
            new com.amazonaws.services.sqs.model.Message()
                    .withMessageAttributes(mapMessageAttributes)
                    .withAttributes(mapAttributes)
                    .withBody(messageBody);

    SQSBytesMessage msg = spy(new SQSBytesMessage(acknowledger, QUEUE_URL, message));

    when(amazonSQSClient.sendMessage(any(SendMessageRequest.class)))
            .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID).withSequenceNumber(SEQ_NUMBER_2));

    producer.sendInternal(destination, msg);

    verify(amazonSQSClient).sendMessage(argThat(new sendMessageRequestMatcher(QUEUE_URL, messageBody, SQSMessage.BYTE_MESSAGE_TYPE, GROUP_ID, DEDUP_ID)));
    verify(msg).setJMSDestination(destination);
    verify(msg).setJMSMessageID("ID:" + MESSAGE_ID);
    verify(msg).setSQSMessageId(MESSAGE_ID);
    verify(msg).setSequenceNumber(SEQ_NUMBER_2);
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:43,代码来源:SQSMessageProducerFifoTest.java

示例10: testConvertToJMSMessageByteTypeAttribute

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Test ConvertToJMSMessage with byte message type
 */
@Test
public void testConvertToJMSMessageByteTypeAttribute() throws JMSException, IOException {

    /*
     * Set up consumer prefetch and mocks
     */

    Map<String,MessageAttributeValue> mapMessageAttributes = new HashMap<String, MessageAttributeValue>();
    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setStringValue(SQSMessage.BYTE_MESSAGE_TYPE);
    messageAttributeValue.setDataType(SQSMessagingClientConstants.STRING);
    mapMessageAttributes.put(SQSMessage.JMS_SQS_MESSAGE_TYPE, messageAttributeValue);

    Map<String, String> mapAttributes = new HashMap<String, String>();
    mapAttributes.put(SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT, "1");

    com.amazonaws.services.sqs.model.Message message = mock(com.amazonaws.services.sqs.model.Message.class);

    // Return message attributes with message type 'BYTE'
    when(message.getMessageAttributes()).thenReturn(mapMessageAttributes);
    when(message.getAttributes()).thenReturn(mapAttributes);

    byte[] byteArray = new byte[] { 1, 0, 'a', 65 };
    when(message.getBody()).thenReturn(Base64.encodeAsString(byteArray));

    /*
     * Convert the SQS message to JMS Message
     */
    javax.jms.Message jsmMessage = consumerPrefetch.convertToJMSMessage(message);

    /*
     * Verify results
     */
    assertTrue(jsmMessage instanceof SQSBytesMessage);
    for (byte b : byteArray) {
        assertEquals(b, ((SQSBytesMessage)jsmMessage).readByte());
    }
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:42,代码来源:SQSMessageConsumerPrefetchTest.java

示例11: testConvertToJMSMessageByteTypeIllegalBody

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Test ConvertToJMSMessage with byte message that contains illegal sqs message body
 */
@Test
public void testConvertToJMSMessageByteTypeIllegalBody() throws JMSException, IOException {

    /*
     * Set up consumer prefetch and mocks
     */

    Map<String,MessageAttributeValue> mapMessageAttributes = new HashMap<String, MessageAttributeValue>();

    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setStringValue(SQSMessage.BYTE_MESSAGE_TYPE);
    messageAttributeValue.setDataType(SQSMessagingClientConstants.STRING);
    mapMessageAttributes.put(SQSMessage.JMS_SQS_MESSAGE_TYPE, messageAttributeValue);

    Map<String, String> mapAttributes = new HashMap<String, String>();
    mapAttributes.put(SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT, "1");

    com.amazonaws.services.sqs.model.Message message = mock(com.amazonaws.services.sqs.model.Message.class);

    // Return message attributes with message type 'BYTE'
    when(message.getMessageAttributes()).thenReturn(mapMessageAttributes);
    when(message.getAttributes()).thenReturn(mapAttributes);
    // Return illegal message body for byte message type
    when(message.getBody()).thenReturn("Text Message");

    /*
     * Convert the SQS message to JMS Message
     */
    try {
        consumerPrefetch.convertToJMSMessage(message);
        fail("Expect JMSException");
    } catch (JMSException jmse) {
        // Expected JMS exception
    }
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:39,代码来源:SQSMessageConsumerPrefetchTest.java

示例12: testConvertToJMSMessageObjectIllegalBody

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Test ConvertToJMSMessage with an object message that contains illegal sqs message body
 */
@Test
public void testConvertToJMSMessageObjectIllegalBody() throws JMSException, IOException {

    /*
     * Set up consumer prefetch and mocks
     */

    Map<String,MessageAttributeValue> mapMessageAttributes = new HashMap<String, MessageAttributeValue>();

    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setStringValue(SQSMessage.OBJECT_MESSAGE_TYPE);
    messageAttributeValue.setDataType(SQSMessagingClientConstants.STRING);
    mapMessageAttributes.put(SQSMessage.JMS_SQS_MESSAGE_TYPE, messageAttributeValue);

    Map<String, String> mapAttributes = new HashMap<String, String>();
    mapAttributes.put(SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT, "1");

    com.amazonaws.services.sqs.model.Message message = mock(com.amazonaws.services.sqs.model.Message.class);
    // Return message attributes with message type 'OBJECT'
    when(message.getMessageAttributes()).thenReturn(mapMessageAttributes);
    when(message.getAttributes()).thenReturn(mapAttributes);
    when(message.getBody()).thenReturn("Some text that does not represent an object");

    /*
     * Convert the SQS message to JMS Message
     */
    ObjectMessage jsmMessage = (ObjectMessage) consumerPrefetch.convertToJMSMessage(message);

    /*
     * Verify results
     */
    try {
        jsmMessage.getObject();
        fail("Expect JMSException");
    } catch (JMSException jmse) {
        // Expected JMS exception
    }
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:42,代码来源:SQSMessageConsumerPrefetchTest.java

示例13: testConvertToJMSMessageTextTypeAttribute

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Test ConvertToJMSMessage with text message with text type attribute
 */
@Test
public void testConvertToJMSMessageTextTypeAttribute() throws JMSException, IOException {

    /*
     * Set up consumer prefetch and mocks
     */

    Map<String,MessageAttributeValue> mapMessageAttributes = new HashMap<String, MessageAttributeValue>();
    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setStringValue(SQSMessage.TEXT_MESSAGE_TYPE);
    messageAttributeValue.setDataType(SQSMessagingClientConstants.STRING);
    mapMessageAttributes.put(SQSMessage.JMS_SQS_MESSAGE_TYPE, messageAttributeValue);

    Map<String, String> mapAttributes = new HashMap<String, String>();
    mapAttributes.put(SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT, "1");

    com.amazonaws.services.sqs.model.Message message = mock(com.amazonaws.services.sqs.model.Message.class);
    // Return message attributes with message type 'TEXT'
    when(message.getMessageAttributes()).thenReturn(mapMessageAttributes);
    when(message.getAttributes()).thenReturn(mapAttributes);
    when(message.getBody()).thenReturn("MessageBody");

    /*
     * Convert the SQS message to JMS Message
     */
    javax.jms.Message jsmMessage = consumerPrefetch.convertToJMSMessage(message);

    /*
     * Verify results
     */
    assertTrue(jsmMessage instanceof SQSTextMessage);
    assertEquals(message.getBody(), "MessageBody");
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:37,代码来源:SQSMessageConsumerPrefetchTest.java

示例14: testSendInternalSQSObjectMessageFromReceivedMessage

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
/**
 * Test sendInternal input with SQSObjectMessage
 */
@Test
public void testSendInternalSQSObjectMessageFromReceivedMessage() throws JMSException, IOException {

    /*
     * Set up non JMS sqs message
     */
    Map<String,MessageAttributeValue> mapMessageAttributes = new HashMap<String, MessageAttributeValue>();

    MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
    messageAttributeValue.setStringValue(SQSMessage.OBJECT_MESSAGE_TYPE);
    messageAttributeValue.setDataType(SQSMessagingClientConstants.STRING);
    mapMessageAttributes.put(SQSMessage.JMS_SQS_MESSAGE_TYPE, messageAttributeValue);

    Map<String, String> mapAttributes = new HashMap<String, String>();
    mapAttributes.put(SQSMessagingClientConstants.APPROXIMATE_RECEIVE_COUNT, "1");

    // Encode an object to byte array
    Integer integer = new Integer("10");
    ByteArrayOutputStream array = new ByteArrayOutputStream(10);
    ObjectOutputStream oStream = new ObjectOutputStream(array);
    oStream.writeObject(integer);
    oStream.close();

    String messageBody = Base64.encodeAsString(array.toByteArray());
    com.amazonaws.services.sqs.model.Message message =
            new com.amazonaws.services.sqs.model.Message()
                    .withMessageAttributes(mapMessageAttributes)
                    .withAttributes(mapAttributes)
                    .withBody(messageBody);

    SQSObjectMessage msg = spy(new SQSObjectMessage(acknowledger, QUEUE_URL, message));

    Map<String, MessageAttributeValue> messageAttributes = createMessageAttribute("object");

    when(amazonSQSClient.sendMessage(any(SendMessageRequest.class)))
            .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID_1))
            .thenReturn(new SendMessageResult().withMessageId(MESSAGE_ID_2));

    producer.sendInternal(destination, msg);

    verify(amazonSQSClient).sendMessage(argThat(new sendMessageRequestMatcher(QUEUE_URL, Arrays.asList(messageBody),
            messageAttributes)));
    verify(msg).setJMSDestination(destination);
    verify(msg).setJMSMessageID("ID:" + MESSAGE_ID_1);
    verify(msg).setSQSMessageId(MESSAGE_ID_1);
}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:50,代码来源:SQSMessageProducerTest.java

示例15: internalTestPropertyToMessageAttribute

import com.amazonaws.services.sqs.model.MessageAttributeValue; //导入方法依赖的package包/类
public void internalTestPropertyToMessageAttribute(SQSMessage sqsText) throws JMSException {

        /*
         * Setup JMS message property
         */
        String booleanProperty = "BooleanProperty";
        String byteProperty = "ByteProperty";
        String shortProperty = "ShortProperty";
        String intProperty = "IntProperty";
        String longProperty = "LongProperty";
        String floatProperty = "FloatProperty";
        String doubleProperty = "DoubleProperty";
        String stringProperty = "StringProperty";
        String objectProperty = "ObjectProperty";

        sqsText.setBooleanProperty(booleanProperty, true);
        sqsText.setByteProperty(byteProperty, (byte)1);
        sqsText.setShortProperty(shortProperty, (short) 2);
        sqsText.setIntProperty(intProperty, 3);
        sqsText.setLongProperty(longProperty, 4L);
        sqsText.setFloatProperty(floatProperty, (float)5.0);
        sqsText.setDoubleProperty(doubleProperty, 6.0);
        sqsText.setStringProperty(stringProperty, "seven");
        sqsText.setObjectProperty(objectProperty, new Integer(8));

        MessageAttributeValue messageAttributeValueBoolean = new MessageAttributeValue();
        messageAttributeValueBoolean.setDataType("Number.Boolean");
        messageAttributeValueBoolean.setStringValue("1");

        MessageAttributeValue messageAttributeValueByte = new MessageAttributeValue();
        messageAttributeValueByte.setDataType("Number.byte");
        messageAttributeValueByte.setStringValue("1");

        MessageAttributeValue messageAttributeValueShort = new MessageAttributeValue();
        messageAttributeValueShort.setDataType("Number.short");
        messageAttributeValueShort.setStringValue("2");

        MessageAttributeValue messageAttributeValueInt = new MessageAttributeValue();
        messageAttributeValueInt.setDataType("Number.int");
        messageAttributeValueInt.setStringValue("3");

        MessageAttributeValue messageAttributeValueLong = new MessageAttributeValue();
        messageAttributeValueLong.setDataType("Number.long");
        messageAttributeValueLong.setStringValue("4");

        MessageAttributeValue messageAttributeValueFloat = new MessageAttributeValue();
        messageAttributeValueFloat.setDataType("Number.float");
        messageAttributeValueFloat.setStringValue("5.0");

        MessageAttributeValue messageAttributeValueDouble = new MessageAttributeValue();
        messageAttributeValueDouble.setDataType("Number.double");
        messageAttributeValueDouble.setStringValue("6.0");

        MessageAttributeValue messageAttributeValueString = new MessageAttributeValue();
        messageAttributeValueString.setDataType("String");
        messageAttributeValueString.setStringValue("seven");

        MessageAttributeValue messageAttributeValueObject = new MessageAttributeValue();
        messageAttributeValueObject.setDataType("Number.int");
        messageAttributeValueObject.setStringValue("8");

        /*
         * Convert property to sqs message attribute
         */
        Map<String, MessageAttributeValue> messageAttribute = producer.propertyToMessageAttribute(sqsText);

        /*
         * Verify results
         */
        assertEquals(messageAttributeValueBoolean, messageAttribute.get(booleanProperty));
        assertEquals(messageAttributeValueByte, messageAttribute.get(byteProperty));
        assertEquals(messageAttributeValueShort, messageAttribute.get(shortProperty));
        assertEquals(messageAttributeValueInt, messageAttribute.get(intProperty));
        assertEquals(messageAttributeValueLong, messageAttribute.get(longProperty));
        assertEquals(messageAttributeValueFloat, messageAttribute.get(floatProperty));
        assertEquals(messageAttributeValueDouble, messageAttribute.get(doubleProperty));
        assertEquals(messageAttributeValueString, messageAttribute.get(stringProperty));
        assertEquals(messageAttributeValueObject, messageAttribute.get(objectProperty));

    }
 
开发者ID:awslabs,项目名称:amazon-sqs-java-messaging-lib,代码行数:81,代码来源:SQSMessageProducerFifoTest.java


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