When you send a Map
into JMS using JmsTemplate
, it is wrapped to the MapMessage
(by default):
else if (object instanceof Map) {
return createMessageForMap((Map<? ,?>) object, session);
}
And you has to be sure that all the key of the map are of String
type and values are primitivies
. That's according a MapMessage
JavaDocs:
/** A {@code MapMessage} object is used to send a set of name-value pairs.
* The names are {@code String} objects, and the values are primitive
* data types in the Java programming language. The names must have a value that
* is not null, and not an empty string. The entries can be accessed
* sequentially or randomly by name. The order of the entries is undefined.
* {@code MapMessage} inherits from the {@code Message} interface
* and adds a message body that contains a Map.
And here is a snippet from the ActiveMQ MarshallingSupport
:
public static void marshalPrimitive(DataOutputStream out, Object value) throws IOException {
if (value == null) {
marshalNull(out);
} else if (value.getClass() == Boolean.class) {
marshalBoolean(out, ((Boolean)value).booleanValue());
} else if (value.getClass() == Byte.class) {
marshalByte(out, ((Byte)value).byteValue());
} else if (value.getClass() == Character.class) {
marshalChar(out, ((Character)value).charValue());
} else if (value.getClass() == Short.class) {
marshalShort(out, ((Short)value).shortValue());
} else if (value.getClass() == Integer.class) {
marshalInt(out, ((Integer)value).intValue());
} else if (value.getClass() == Long.class) {
marshalLong(out, ((Long)value).longValue());
} else if (value.getClass() == Float.class) {
marshalFloat(out, ((Float)value).floatValue());
} else if (value.getClass() == Double.class) {
marshalDouble(out, ((Double)value).doubleValue());
} else if (value.getClass() == byte[].class) {
marshalByteArray(out, (byte[])value);
} else if (value.getClass() == String.class) {
marshalString(out, (String)value);
} else if (value.getClass() == UTF8Buffer.class) {
marshalString(out, value.toString());
} else if (value instanceof Map) {
out.writeByte(MAP_TYPE);
marshalPrimitiveMap((Map<String, Object>)value, out);
} else if (value instanceof List) {
out.writeByte(LIST_TYPE);
marshalPrimitiveList((List<Object>)value, out);
} else {
throw new IOException("Object is not a primitive: " + value);
}
}
So, your Record
won't be accepted.
You need to consider do not use Map
for JMS message and make your Record
as Serializable
to be able to send it over JMS. Or consider to use some other MessageConverter
, not SimpleMessageConverter
which is default. For example it seems for me a MappingJackson2MessageConverter
should be good for you.
does not work
? Maybe you have some error in logs? Maybe yourRecord
is just notSerializable
? – Artem Bilan