-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
import { RabbitMQConnection } from 'building-blocks/rabbitmq/rabbitmq-connection'; | ||
import { container } from 'tsyringe'; | ||
import { Rabbitmq } from 'building-blocks/rabbitmq/rabbitmq'; | ||
import { RabbitmqConnectionOptions } from 'building-blocks/rabbitmq/rabbitmq-connection-options-builder'; | ||
import { IPublisher, Publisher } from 'building-blocks/rabbitmq/rabbitmq-publisher'; | ||
import { RabbitmqOptions } from 'building-blocks/rabbitmq/rabbitmq-options-builder'; | ||
|
||
export const initialRabbitmq = async (options?: RabbitmqOptions): Promise<RabbitMQConnection> => { | ||
const rabbitMQConnection = container.resolve(RabbitMQConnection); | ||
export const initialRabbitmq = async (options?: RabbitmqConnectionOptions): Promise<void> => { | ||
const rabbitmq = container.resolve(Rabbitmq); | ||
|
||
await rabbitMQConnection.createConnection((optionsBuilder) => { | ||
optionsBuilder.host = options?.host; | ||
optionsBuilder.port = options?.port; | ||
optionsBuilder.username = options?.username; | ||
optionsBuilder.password = options?.password; | ||
}); | ||
|
||
container.register<IPublisher>('IPublisher', Publisher); | ||
|
||
return rabbitMQConnection; | ||
await rabbitmq | ||
.createConnection((builder) => { | ||
builder | ||
.host(options?.host) | ||
.port(options?.port) | ||
.username(options?.username) | ||
.password(options?.password); | ||
}) | ||
.then((c) => { | ||
container.register<IPublisher>('IPublisher', Publisher); | ||
}); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export declare class RabbitmqConnectionOptions { | ||
host: string; | ||
port: number; | ||
username: string; | ||
password: string; | ||
} | ||
export declare class RabbitmqConnectionOptionsBuilder { | ||
private _options; | ||
host(value: string): RabbitmqConnectionOptionsBuilder; | ||
port(value: number): RabbitmqConnectionOptionsBuilder; | ||
username(value: string): RabbitmqConnectionOptionsBuilder; | ||
password(value: string): RabbitmqConnectionOptionsBuilder; | ||
build(): RabbitmqConnectionOptions; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export class RabbitmqConnectionOptions { | ||
host: string; | ||
port: number; | ||
username: string; | ||
password: string; | ||
} | ||
|
||
export class RabbitmqConnectionOptionsBuilder { | ||
private _options: RabbitmqConnectionOptions = new RabbitmqConnectionOptions(); | ||
|
||
host(value: string): RabbitmqConnectionOptionsBuilder { | ||
this._options.host = value; | ||
return this; | ||
} | ||
|
||
port(value: number): RabbitmqConnectionOptionsBuilder { | ||
this._options.port = value; | ||
return this; | ||
} | ||
|
||
username(value: string): RabbitmqConnectionOptionsBuilder { | ||
this._options.username = value; | ||
return this; | ||
} | ||
|
||
password(value: string): RabbitmqConnectionOptionsBuilder { | ||
this._options.password = value; | ||
return this; | ||
} | ||
|
||
build(): RabbitmqConnectionOptions { | ||
return this._options; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.