micronaut-projects / micronaut-jms

Integration between Micronaut and JMS
Apache License 2.0
14 stars 14 forks source link

BytesMessage not working for Topic send and receive #250

Closed yuecelm closed 2 years ago

yuecelm commented 2 years ago

Expected Behavior

1) send(byte[] message) should serialize to BytesMessage 2) DefaultSerializerDeserializer.serializeBytes throws no exception 3) DefaultSerializerDeserializer.deserializeBytes should be called once 4) receive(byte[] message) should be the same byte array as in step 1

Actual Behaviour

1) send(byte[] message) serialize to ObjectMessage 2) DefaultSerializerDeserializer.serializeBytes throws an exception (after fixing step 1.) 3) DefaultSerializerDeserializer.deserializeBytes is called twice 4) receive(byte[] message) receives the same byte length as in step 1, but filled with zeroes

Steps To Reproduce

git clone -b issue/250 https://github.com/yuecelm/micronaut-jms.git cd micronaut-jms ./gradlew :tests:tasks-activemq-classic:test -i --rerun-tasks

observe the following output:

TasksSpec > should process tasks STANDARD_OUT
    serializeBytes: [49]
    deserializeBytes: [49]
    deserializeBytes: [0]
    00:23:15.449 [pool-2-thread-1] INFO  example.TasksListener - Received byte[]: [0]
    serializeBytes: [50]
    deserializeBytes: [50]
    deserializeBytes: [0]
    00:23:16.422 [pool-2-thread-1] INFO  example.TasksListener - Received byte[]: [0]
    serializeBytes: [51]
    deserializeBytes: [51]
    deserializeBytes: [0]
    00:23:17.425 [pool-2-thread-1] INFO  example.TasksListener - Received byte[]: [0]
    serializeBytes: [52]
    deserializeBytes: [52]
    deserializeBytes: [0]
    00:23:18.423 [pool-2-thread-1] INFO  example.TasksListener - Received byte[]: [0]

but would expect something like this:

TasksSpec > should process tasks STANDARD_OUT
    serializeBytes: [49]
    deserializeBytes: [49]
    00:23:15.449 [pool-2-thread-1] INFO  example.TasksListener - Received byte[]: [49]
    serializeBytes: [50]
    deserializeBytes: [50]
    00:23:16.422 [pool-2-thread-1] INFO  example.TasksListener - Received byte[]: [50]
    serializeBytes: [51]
    deserializeBytes: [51]
    00:23:17.425 [pool-2-thread-1] INFO  example.TasksListener - Received byte[]: [51]
    serializeBytes: [52]
    deserializeBytes: [52]
    00:23:18.423 [pool-2-thread-1] INFO  example.TasksListener - Received byte[]: [52]

Environment Information

No response

Example Application

  1. and 2. already solved in this branch: https://github.com/yuecelm/micronaut-jms/tree/issue/250

Version

git head of Micronaut JMS, also observed with latest release 2.0.0 M1

yuecelm commented 2 years ago

1) can be fixed by having BYTES before OBJECT in MessageType

yuecelm commented 2 years ago
  1. can be fixed by replacing message.readBytes(body) to message.writeBytes(body), as suggested in #238
yuecelm commented 2 years ago
  1. second call will ending in zero filled byte array, reason for second call is unknown
yuecelm commented 2 years ago

would suggest testcases: 1) check all possible message types explicitly by triggering send(<T> message) 2) send/receive loop for each message type, currently only ObjectMessage is tested

yuecelm commented 2 years ago

I also suspect the same problem comes up with the Queue annotation

lukaselmer commented 2 years ago

see also https://github.com/micronaut-projects/micronaut-jms/issues/238 and https://github.com/micronaut-projects/micronaut-jms/issues/239

yuecelm commented 2 years ago

solved the issue, but it feels more like a workaround for calling the deserializer twice: https://github.com/yuecelm/micronaut-jms/commit/669be92ecb290ac86ad1923c96893cf0a2da5d2d

graemerocher commented 2 years ago

@spre001 please take a look