LrSqsMessageAttributeValue.dataType

Returns the data type of the attribute as a String.

public String dataType()

Return values

This function returns a String object that represents the type of the data that it holds. This can be String, Number (for Integer and Double), or Binary.

Example

Copy code
public int action() throws Throwable {
        
        LrSqsClient.initClient(region, standardQueueUrl);
        
        LrSqsMessageAttributeValue intValue = LrSqsClient.createMessageAttributeValueInt(24);
        lr.output_message("type: " + intValue.dataType());
        if (intValue.dataType()=="Number"){
            int num = intValue.intValue();
            String s = intValue.stringValue();
            double d = intValue.doubleValue();
        }
        
        LrSqsMessageAttributeValue stringVal = LrSqsClient.createMessageAttributeValueString("2.4");
        lr.output_message("type: " + stringVal.dataType());
        double d = stringVal.doubleValue();        // the value can be converted to double
        
        LrSqsMessageAttributeValue stringVal2 = LrSqsClient.createMessageAttributeValueString("myAttribute");
        lr.output_message("type: " + stringVal2.dataType());
        //double d = stringVal2.doubleValue();        // this line will throw exception - value cannot be converted to double.
        //byte[] b = stringVal2.binaryValue();        // if the attribute is not binary, an exception will be thrown.
        
        LrSqsMessageAttributeValue binaryVal = LrSqsClient.createMessageAttributeValueBinary("binaryAttrib");
        lr.output_message("type: " + binaryVal.dataType());
        byte[] b = binaryVal.binaryValue();
        byte[] b_copy = binaryVal.binaryValueCopy();
        
        LrSqsClient.closeClient();

        return 0;
    }