Comments (4)
hi @vsabirov, I had a read through the rabbit implementation again. Generally one of the goals of this library is to abstract away transport-specific features so that they're largely interchangeable. With that said, the ability to specify custom headers is understandable and I wanted to confirm some behaviour with you.
If you were to do Bus.publish(yourEvent, { attributes: { 'x-delay': 100 } })
then you'd expect this to be added directly against the header.
Currently per rabbitmq-transport.ts:367
this is being serialized against a different key like attributes: JSON.stringify({ 'x-delay': 100 })
ie:
Would this work for you if all attributes were spread onto the headers? ie:
headers: {
...messageOptions.attributes
}
from bus.
@adenhertog Perhaps the ability to specify transport-agnostic attributes in a special header should be kept as is. Sure, it will work fine, however i'm afraid that the user can overwrite some special RMQ headers by accident and will be forced to rename their attributes to avoid collisions.
Perhaps something like
const rawHeaders = messageOptions.attributes.rawHeaders
and
headers: {
attributes: messageOptions.attributes ? JSON.stringify(messageOptions.attributes) : undefined,
stickyAttributes: messageOptions.stickyAttributes ? JSON.stringify(messageOptions.stickyAttributes) : undefined
...rawHeaders
}
And to use that you'll just have to specify a rawHeaders
object in the message options that will be additionally spread into the headers.
from bus.
@vsabirov I'm happy with what you've proposed - the reasoning makes a lot of sense. I can't get around to this immediately, but I'm open to accepting PRs if you need this soon
from bus.
@adenhertog I propose to hide access to internal attributes from regular use with symbols. The user should understand that this is an internal API.
I see a solution to this problem as follows
@node-ts/bus-messages
export kInternalAttributes = Symbol('@node-ts/bus-messages/internal-attributes')
export type InternalAttributes<T> = T
export interface MessageAttributes<
AttributesType extends MessageAttributeMap = MessageAttributeMap,
StickyAttributesType extends MessageAttributeMap = MessageAttributeMap,
InternalAttributesType = InternalAttributes<unknown>
>
correlationId?: Uuid;
attributes: AttributesType;
stickyAttributes: StickyAttributesType;
[kInternalAttributes]: InternalAttributesType
}
@node-ts/bus-rabbitmq
export const kRabbitMQHeaders = Symbol('@node-ts/bus-rabbitmq/rabbitmq-headers')
export interface RabbitMQInternalAttributes = {
headers: MessageAttributeMap
}
private async publishMessage(
message: Message,
messageOptions: MessageAttributes<..., ..., RabbitMQInternalAttributes> = { attributes: {}, stickyAttributes: {}, internalAttributes: {} }
): Promise<void> {
await this.assertExchange(message.$name)
const payload = this.coreDependencies.messageSerializer.serialize(message)
const internalAttributes = messageOptions[kInternalAttributes]
this.channel.publish(message.$name, '', Buffer.from(payload), {
correlationId: messageOptions.correlationId,
messageId: uuid.v4(),
headers: {
attributes: messageOptions.attributes
? JSON.stringify(messageOptions.attributes)
: undefined,
stickyAttributes: messageOptions.stickyAttributes
? JSON.stringify(messageOptions.stickyAttributes)
: undefined
...internalAttributes.headers
}
})
}
Usage
import { kInternalAttributes } from '@node-ts/bus-messages'
bus.publish(new Message(), {
[kInternalAttributes]: { // typed
headers: {
'x-delay': 5000
}
}
})
This is a draft solution, I'm just suggesting a concept
from bus.
Related Issues (20)
- Construct workflows using container during mapping
- Port middleware over to master HOT 1
- RabbitMQ queue and exchange setup HOT 8
- The memory-queue is inappropriately deleting messages HOT 1
- Broken links in docs HOT 1
- Delay a retry by X seconds HOT 1
- Vulnerability in url-parse - dependency of amqplib HOT 1
- Rabbitmq transport polling HOT 2
- IoC with loopback HOT 4
- Named export <nameExport> not found HOT 2
- [bus-class-serializer]: package.json missing attributes HOT 1
- [Bug] Rabbitmq-transport.ts does not have reconnection if channel gets disconnected by some reasons
- How to setup DI container, when workflow needs the bus instance HOT 2
- Open to update `bus-sqs` to aws-sdk v3? HOT 1
- Support Mognodb Persistence for Workflows
- Problem with lodash and persisting workflow state
- Stuck workflows with error: "No existing workflow state found for message. Ignoring"
- [Feat] Support passing message and message context to Container Adapter HOT 1
- Persistent messages are not supported. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bus.