Skip to content

As a library user I want to create a Publisher so I can publish messages #6

@l4mby

Description

@l4mby

Create and close the publisher

const publisher = await connection.createPublisher({ exchange: { name: "foo", key: "bar" }})

await publisher.close()

Publish a message and check the outcome

const message = createAmqpMessage({ body: "Hello World" })

const publishResult = await publisher.publish(message)
switch (publishResult.OutcomeState) {
    case OutcomeState.ACCEPTED:
        # the broker accepted (confirmed) the message
    case OutcomeState.RELEASED:
        # the broker could not route the message anywhere 
    case OutcomeState.REJECTED:
        # at least one queue rejected the message
}

Create the publisher that can publish on a queue

const publisher = await connection.createPublisher({ queue: { name: "foo" }})

The publisher can also be created without a target, and then it will have to publish targeted messages

const publisher = await connection.createPublisher()

const message = createAmqpMessage({ body: "Hello World", destination:  { exchange: { name: "foo", key: "bar" }}})

\\ or

const message = createAmqpMessage({ body: "Hello World", destination:  { queue: { name: "foo" }}})

await publisher.publish(message)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions