Skip to content

feat: handle binary buffers with messageBuffer#3

Merged
Julien-R44 merged 1 commit intomainfrom
feat/binary-buffer
May 17, 2024
Merged

feat: handle binary buffers with messageBuffer#3
Julien-R44 merged 1 commit intomainfrom
feat/binary-buffer

Conversation

@Julien-R44
Copy link
Member

The issue is well described here: Julien-R44/bentocache#19

Basically: when using a custom encoder which returns a buffer with binary data, then it will not work. because the message event emitted by ioredis automatically converts buffers

When dealing with binary data then ioredis recommends using the messageBuffer event: https://github.com/redis/ioredis?tab=readme-ov-file#pubsub

image


Suggested solution: when we create our bus with the redis transport, we can now pass the useMessageBuffer option which will make the bus listen on the messageBuffer event rather than message.

const manager = new BusManager({
  transports: {
    redis: {
      transport: redis(
        {
          useMessageBuffer: true, // here
          host: 'localhost',
          port: 6379,
        },
        new BinaryEncoder() // pass our custom encoder
      ),
    },
  },
})

Breaking Change: The encoder signature has changed. The decode function now accepts a string or a Buffer. I think we can release that this in a minor release, since i think nobody has created a custom encoder yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant