Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AMQP publisherManager #144

Merged
merged 8 commits into from
May 18, 2024
Merged

Conversation

kibertoad
Copy link
Owner

No description provided.

@kibertoad kibertoad requested review from CarlosGamero and dariacm May 18, 2024 17:09
'lib/**/*.test.ts',
'test/**/*.*',
'lib/types/**/*.*',
'lib/AmqpExchangePublisherManager.ts',
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's problematic to write tests for this functionality, as we don't yet have any logic in place for autocreating exchanges and autosubscribing queues. this will be done next.

publishOptions: {},
}

export class AbstractAmqpQueuePublisher<
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a replacement for previously existing AbstractAmqpPublisher.

It's a breaking change.

publishOptions: Options.Publish
}

export class AbstractAmqpExchangePublisher<
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exposes RabbitMQ PubSub functionality (SNS-like).
previously we only had direct publishing to queues (SQS-like)

) {
super(dependencies, {
...options,
// FixMe exchange publisher doesn't need queue at all
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be addressed during auto-init rework, as we need to implement exchange and subscription support

z.infer<T['schema']>,
'type' | 'payload'
> & { id?: string }
export type MessagePublishType<T extends CommonEventDefinition> = z.infer<T['schema']>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, previous Pick-based implementation was breaking payload type inference during publishing. TS started accepting any combination of valid message types and payloads, and not enforcing that they belong to the same message

@@ -50,7 +43,13 @@ describe('SnsPublisherManager', () => {
await fakeConsumer.start()

// When
const publishedMessage = await publisherManager.publish(TestEvents.created.snsTopic, message)
const publishedMessage = await publisherManager.publish(TestEvents.created.snsTopic, {
...publisherManager.resolveBaseFields(),
Copy link
Owner Author

@kibertoad kibertoad May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we could figure out a better way, that would both preserve specific payload type here, and not require explicitly passing all of the core fields, but so far I wasn't very successful in this.

publisherManager.publish(TestEvents.created.snsTopic, {
...publisherManager.resolveBaseFields(),
payload: {
// @ts-expect-error This should be causing a compilation error
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test can be used for checking the payload/type inference logic

} from './AmqpQueuePublisherManager'
import { CommonAmqpExchangePublisherFactory } from './CommonAmqpPublisherFactory'

import Omit = util.Omit
Copy link
Collaborator

@CarlosGamero CarlosGamero May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 nit: Importing omit could cause confusing with TS Omit, I would prefer using util.Omit or even z.util.Omit (I think it is coming from zod, sorry if I misunderstood it) to make it more specific. But this is a very nitpicky comment, feel free to ignore

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, this was autoresolve by WebStorm, not intentional. I wanted to use TS Omit

T extends AbstractAmqpPublisher<EventType, MO>,
MO,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
PO extends Omit<AMQPPublisherOptions<any>, 'creationConfig'>,
Copy link
Collaborator

@CarlosGamero CarlosGamero May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if possible, but just wondering if could be possible to use unknown instead of any

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not unknown, but I'll try to wrestle with types to make this unnecessary

@kibertoad kibertoad merged commit 55ae060 into main May 18, 2024
5 checks passed
@kibertoad kibertoad deleted the feat/amqp-publisher-manager branch May 18, 2024 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants