Fix AmqpMessageDispatcherServiceTest.testSendCancelRequest - set action tenant (#2098)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -22,24 +22,19 @@ import org.springframework.messaging.converter.MessageConversionException;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
/**
|
||||
* A customize message converter for the spring cloud events. The converter is
|
||||
* registered for the application/binary+protostuff type.
|
||||
*
|
||||
* The clazz-type-information is encoded into the message payload infront with a
|
||||
* length of {@link #EVENT_TYPE_LENGTH}. This is necessary due in case of
|
||||
* rabbitMQ batching the message headers will be merged together and custom
|
||||
* message header information will get lost. So in this implementation the
|
||||
* information about the event-type is encoded in the payload of the message
|
||||
* directly using the encoded values of {@link EventType}.
|
||||
* A customize message converter for the spring cloud events. The converter is registered for the application/binary+protostuff type.
|
||||
* <p/>
|
||||
* The clazz-type-information is encoded into the message payload infront with a length of {@link #EVENT_TYPE_LENGTH}. This is necessary
|
||||
* due in case of rabbitMQ batching the message headers will be merged together and custom message header information will get lost.
|
||||
* So in this implementation the information about the event-type is encoded in the payload of the message directly using the encoded
|
||||
* values of {@link EventType}.
|
||||
*/
|
||||
@Slf4j
|
||||
public class BusProtoStuffMessageConverter extends AbstractMessageConverter {
|
||||
|
||||
public static final MimeType APPLICATION_BINARY_PROTOSTUFF = new MimeType("application", "binary+protostuff");
|
||||
|
||||
/**
|
||||
* The length of the class type length of the payload.
|
||||
*/
|
||||
/** The length of the class type length of the payload. */
|
||||
private static final byte EVENT_TYPE_LENGTH = 2;
|
||||
|
||||
public BusProtoStuffMessageConverter() {
|
||||
@@ -52,8 +47,7 @@ public class BusProtoStuffMessageConverter extends AbstractMessageConverter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convertFromInternal(final Message<?> message, final Class<?> targetClass,
|
||||
final Object conversionHint) {
|
||||
public Object convertFromInternal(final Message<?> message, final Class<?> targetClass, final Object conversionHint) {
|
||||
final Object objectPayload = message.getPayload();
|
||||
if (objectPayload instanceof byte[] payload) {
|
||||
final byte[] clazzHeader = extractClazzHeader(payload);
|
||||
@@ -66,13 +60,9 @@ public class BusProtoStuffMessageConverter extends AbstractMessageConverter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object convertToInternal(final Object payload, final MessageHeaders headers,
|
||||
final Object conversionHint) {
|
||||
|
||||
protected Object convertToInternal(final Object payload, final MessageHeaders headers, final Object conversionHint) {
|
||||
final byte[] clazzHeader = writeClassHeader(payload.getClass());
|
||||
|
||||
final byte[] writeContent = writeContent(payload);
|
||||
|
||||
return mergeClassHeaderAndContent(clazzHeader, writeContent);
|
||||
}
|
||||
|
||||
@@ -132,4 +122,4 @@ public class BusProtoStuffMessageConverter extends AbstractMessageConverter {
|
||||
final LinkedBuffer buffer = LinkedBuffer.allocate();
|
||||
return ProtobufIOUtil.toByteArray(clazzEventType, schema, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,10 +86,8 @@ public class EventType {
|
||||
|
||||
private int value;
|
||||
|
||||
/**
|
||||
* The associated event-type-value must remain the same as initially
|
||||
* declared. Otherwise, messages cannot correctly de-serialized.
|
||||
*/
|
||||
// The associated event-type-value must remain the same as initially
|
||||
// declared. Otherwise, messages cannot correctly de-serialized.
|
||||
static {
|
||||
// target
|
||||
TYPES.put(1, TargetCreatedEvent.class);
|
||||
@@ -190,10 +188,12 @@ public class EventType {
|
||||
* does not have a {@link EventType}.
|
||||
*/
|
||||
public static EventType from(final Class<?> clazz) {
|
||||
final Optional<Integer> foundEventType = TYPES.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().equals(clazz)).map(Entry::getKey).findAny();
|
||||
|
||||
return foundEventType.map(EventType::new).orElse(null);
|
||||
return TYPES.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().equals(clazz))
|
||||
.map(Entry::getKey)
|
||||
.findAny()
|
||||
.map(EventType::new)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public Class<?> getTargetClass() {
|
||||
|
||||
Reference in New Issue
Block a user