/** * <p> * Amazon SNS supports the following logical data types: String, String.Array, Number, and Binary. For more * information, see <a * href="http://docs.aws.amazon.com/sns/latest/dg/SNSMessageAttributes.html#SNSMessageAttributes.DataTypes">Message * Attribute Data Types</a>. * </p> * * @param dataType * Amazon SNS supports the following logical data types: String, String.Array, Number, and Binary. For more * information, see <a * href="http://docs.aws.amazon.com/sns/latest/dg/SNSMessageAttributes.html#SNSMessageAttributes.DataTypes" * >Message Attribute Data Types</a>. * @return Returns a reference to this object so that method calls can be chained together. */ public MessageAttributeValue withDataType(String dataType) { setDataType(dataType); return this; }
public MessageAttributeValue unmarshall(StaxUnmarshallerContext context) throws Exception { MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return messageAttributeValue; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("DataType", targetDepth)) { messageAttributeValue.setDataType(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("StringValue", targetDepth)) { messageAttributeValue.setStringValue(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("BinaryValue", targetDepth)) { messageAttributeValue.setBinaryValue(ByteBufferStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return messageAttributeValue; } } } }
final MessageAttributeValue value = new MessageAttributeValue(); value.setStringValue(context.getProperty(entry.getKey()).evaluateAttributeExpressions(flowFile).getValue()); value.setDataType("String"); request.addMessageAttributesEntry(entry.getKey().getName(), value);
messageAttributeValue.setDataType(StringStaxUnmarshaller.getInstance() .unmarshall(context)); continue;
@Override protected Void run() throws Exception { final String topicArn = this.step.getTopicArn(); final String subject = this.step.getSubject(); final String message = this.step.getMessage(); final Map<String, String> messageAttributes = this.step.getMessageAttributes(); TaskListener listener = this.getContext().get(TaskListener.class); AmazonSNS snsClient = AWSClientFactory.create(AmazonSNSClientBuilder.standard(), this.getContext()); listener.getLogger().format("Publishing notification %s to %s %n", subject, topicArn); PublishRequest publishRequest = new PublishRequest() .withTopicArn(topicArn).withMessage(message).withSubject(subject); if (messageAttributes != null && !messageAttributes.isEmpty()) { for (Map.Entry<String, String> entry : messageAttributes.entrySet()) { MessageAttributeValue value = new MessageAttributeValue(); value.setStringValue(entry.getValue()); value.setDataType(STRING_DATATYPE); publishRequest.addMessageAttributesEntry(entry.getKey(), value); } } PublishResult result = snsClient.publish(publishRequest); listener.getLogger().format("Message published as %s %n", result.getMessageId()); return null; }
final MessageAttributeValue value = new MessageAttributeValue(); value.setStringValue(context.getProperty(entry.getKey()).evaluateAttributeExpressions(flowFile).getValue()); value.setDataType("String"); request.addMessageAttributesEntry(entry.getKey().getName(), value);
messageAttributeValue.setDataType(StringStaxUnmarshaller.getInstance() .unmarshall(context)); continue;