Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 14 additions & 170 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"globals": "^16.2.0",
"got": "^14.4.7",
"prettier": "3.5.3",
"ts-node": "^10.9.2",
"tsup": "^8.5.0",
"typescript": "^5.8.3",
"typescript-eslint": "^8.33.1",
Expand Down
17 changes: 17 additions & 0 deletions src/connection.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { ConnectionEvents, create_container, Connection as RheaConnection } from "rhea"
import { AmqpManagement, Management } from "./management.js"
import { EnvironmentParams } from "./environment.js"
import { AmqpPublisher, Publisher } from "./publisher.js"
import { DestinationOptions } from "./message.js"

export interface Connection {
close(): Promise<boolean>
isOpen(): boolean
management(): Management
createPublisher(options?: DestinationOptions): Promise<Publisher>
get publishers(): Map<string, Publisher>
}

export class AmqpConnection implements Connection {
private _publishers: Map<string, Publisher> = new Map<string, Publisher>()

static async create(params: EnvironmentParams) {
const connection = await AmqpConnection.open(params)
const topologyManagement = await AmqpManagement.create(connection)
Expand Down Expand Up @@ -43,6 +49,7 @@ export class AmqpConnection implements Connection {
return rej(new Error("Connection error: " + context.connection.error))
})

this._publishers.forEach((p) => p.close())
this.connection.close()
})
}
Expand All @@ -51,6 +58,16 @@ export class AmqpConnection implements Connection {
return this.topologyManagement
}

async createPublisher(options?: DestinationOptions): Promise<Publisher> {
const publisher = await AmqpPublisher.createFrom(this.connection, this._publishers, options)
this._publishers.set(publisher.id, publisher)
return publisher
}

public get publishers(): Map<string, Publisher> {
return this._publishers
}

public isOpen(): boolean {
return this.connection ? this.connection.is_open() : false
}
Expand Down
2 changes: 1 addition & 1 deletion src/message_builder.ts → src/link_message_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export enum AmqpEndpoints {

export const ME = "$me"

export class MessageBuilder {
export class LinkMessageBuilder {
private messageId: string = generate_uuid()
private to: string = ""
private replyTo: string = ME
Expand Down
Loading