@maxjoehnk/masstransit-rabbitmq
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -9,2 +9,3 @@ import { ReceiveEndpointConfigurator, ReceiveEndpointOptions } from './receiveEndpoint'; | ||
import { HostSettings, RabbitMqHostAddress } from './RabbitMqEndpointAddress'; | ||
import { AsyncReceiveEndpointConfigurator } from './AsyncReceiveEndpoint'; | ||
export interface Bus { | ||
@@ -16,2 +17,3 @@ hostAddress: RabbitMqHostAddress; | ||
receiveEndpoint(queueName: string, config: (endpoint: ReceiveEndpointConfigurator) => void, options?: ReceiveEndpointOptions): void; | ||
asyncReceiveEndpoint(queueName: string, config: (endpoint: AsyncReceiveEndpointConfigurator) => void, options?: ReceiveEndpointOptions): void; | ||
sendEndpoint(args: SendEndpointArguments): SendEndpoint; | ||
@@ -18,0 +20,0 @@ requestClient<TRequest extends MessageMap, TResponse extends MessageMap>(args: RequestClientArguments): RequestClient<TRequest, TResponse>; |
@@ -72,3 +72,3 @@ var __extends = (this && this.__extends) || (function () { | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "events", "amqplib", "./receiveEndpoint", "./util", "guid-typescript", "./requestClient", "./RabbitMqEndpointAddress"], factory); | ||
define(["require", "exports", "events", "amqplib", "./receiveEndpoint", "./util", "guid-typescript", "./requestClient", "./RabbitMqEndpointAddress", "./AsyncReceiveEndpoint"], factory); | ||
} | ||
@@ -85,2 +85,3 @@ })(function (require, exports) { | ||
var RabbitMqEndpointAddress_1 = require("./RabbitMqEndpointAddress"); | ||
var AsyncReceiveEndpoint_1 = require("./AsyncReceiveEndpoint"); | ||
var MassTransitBus = /** @class */ (function (_super) { | ||
@@ -94,3 +95,3 @@ __extends(MassTransitBus, _super); | ||
_this_1._retryIntervalInSeconds = 3; | ||
_this_1.busEndpoint = _this_1.receiveEndpoint("bus-" + guid_typescript_1.Guid.create().toString(), function (config) { | ||
_this_1.busEndpoint = _this_1.receiveEndpoint("bus-".concat(guid_typescript_1.Guid.create().toString()), function (config) { | ||
config.options.durable = false; | ||
@@ -102,3 +103,3 @@ config.options.autoDelete = true; | ||
.catch(function () { return function (err) { return setImmediate(function () { | ||
throw new Error("Unexpected code block reached: " + err.message + "\n" + err.stack); | ||
throw new Error("Unexpected code block reached: ".concat(err.message, "\n") + err.stack); | ||
}); }; }); | ||
@@ -127,2 +128,23 @@ return _this_1; | ||
}; | ||
/** | ||
* Connects a receive endpoint to the bus | ||
* This endpoint waits for a promise to resolve before acknowledging received messages. | ||
* | ||
* @remarks | ||
* Once connected, the receive endpoint will remain connected until disconnected | ||
* | ||
* @param queueName - The input queue name | ||
* @param cb - The configuration callback, used to add message handlers, etc. | ||
* @param options - Options for the receive endpoint, such as queue/exchange properties, etc. | ||
* @returns Nothing yet, but should return the receive endpoint so that it can be stopped | ||
* | ||
*/ | ||
MassTransitBus.prototype.asyncReceiveEndpoint = function (queueName, cb, options) { | ||
var _this_1 = this; | ||
var _a; | ||
if (options === void 0) { options = receiveEndpoint_1.defaultReceiveEndpointOptions; } | ||
var endpoint = new AsyncReceiveEndpoint_1.AsyncReceiveEndpoint(this, queueName, cb, __assign(__assign({}, receiveEndpoint_1.defaultReceiveEndpointOptions), options)); | ||
(_a = this.connection) === null || _a === void 0 ? void 0 : _a.then(function (connection) { return endpoint.onConnect({ hostAddress: _this_1.hostAddress, connection: connection }); }); | ||
return endpoint; | ||
}; | ||
MassTransitBus.prototype.sendEndpoint = function (args) { | ||
@@ -184,3 +206,3 @@ return this.busEndpoint.sendEndpoint(args); | ||
.catch(function () { return function (err) { return setImmediate(function () { | ||
throw new Error("Unexpected code block reached: " + err.message + "\n" + err.stack); | ||
throw new Error("Unexpected code block reached: ".concat(err.message, "\n") + err.stack); | ||
}); }; }); | ||
@@ -205,3 +227,3 @@ this.stopped = false; | ||
_a.trys.push([1, 3, , 4]); | ||
this.connection = (0, amqplib_1.connect)(this.hostAddress + '?heartbeat=60'); | ||
this.connection = (0, amqplib_1.connect)(this.hostAddress + '?heartbeat=60', { clientProperties: { connection_name: this.hostAddress.name } }); | ||
return [4 /*yield*/, this.connection]; | ||
@@ -242,3 +264,3 @@ case 2: | ||
.catch(function () { return function (err) { return setImmediate(function () { | ||
throw new Error("Unexpected code block reached: " + err.message + "\n" + err.stack); | ||
throw new Error("Unexpected code block reached: ".concat(err.message, "\n") + err.stack); | ||
}); }; }); | ||
@@ -245,0 +267,0 @@ }; |
@@ -6,2 +6,3 @@ import { MessageContext } from './messageContext'; | ||
import { ReceiveEndpoint } from './receiveEndpoint'; | ||
import { AsyncReceiveEndpoint } from './AsyncReceiveEndpoint'; | ||
export interface ConsumeContext<T extends object> extends MessageContext { | ||
@@ -27,3 +28,3 @@ message: T; | ||
message: T; | ||
receiveEndpoint: ReceiveEndpoint; | ||
receiveEndpoint: ReceiveEndpoint | AsyncReceiveEndpoint; | ||
} |
@@ -22,3 +22,3 @@ (function (factory) { | ||
MessageType.prototype.toString = function () { | ||
return "urn:message:" + this.ns + ":" + this.name; | ||
return "urn:message:".concat(this.ns, ":").concat(this.name); | ||
}; | ||
@@ -29,3 +29,3 @@ MessageType.prototype.toMessageType = function () { | ||
MessageType.prototype.toExchange = function () { | ||
return this.ns + ":" + this.name; | ||
return "".concat(this.ns, ":").concat(this.name); | ||
}; | ||
@@ -32,0 +32,0 @@ MessageType.defaultNamespace = 'Messages'; |
@@ -7,2 +7,3 @@ export declare class RabbitMqHostAddress { | ||
protocol: string; | ||
name?: string; | ||
constructor(settings: HostSettings); | ||
@@ -20,2 +21,3 @@ static parseVirtualHost(url: URL): string; | ||
heartbeat?: number; | ||
name?: string; | ||
} | ||
@@ -22,0 +24,0 @@ export declare class RabbitMqEndpointAddress { |
@@ -19,2 +19,3 @@ (function (factory) { | ||
this.port = settings.port; | ||
this.name = settings.name; | ||
if (settings.ssl) { | ||
@@ -43,3 +44,3 @@ this.protocol = 'amqps:'; | ||
if (!url) | ||
throw new Error("Invalid host address: " + address); | ||
throw new Error("Invalid host address: ".concat(address)); | ||
var ssl; | ||
@@ -58,3 +59,3 @@ var port; | ||
default: | ||
throw new Error("Invalid protocol: " + url.protocol); | ||
throw new Error("Invalid protocol: ".concat(url.protocol)); | ||
} | ||
@@ -84,6 +85,6 @@ var host = url.host; | ||
RabbitMqHostAddress.prototype.toUrl = function () { | ||
var url = new URL(this.protocol + "//" + this.host); | ||
var url = new URL("".concat(this.protocol, "//").concat(this.host)); | ||
if (this.port && this.port !== 5672) | ||
url.port = this.port.toString(); | ||
url.pathname = this.virtualHost === '/' ? '/' : "/" + encodeURIComponent(this.virtualHost); | ||
url.pathname = this.virtualHost === '/' ? '/' : "/".concat(encodeURIComponent(this.virtualHost)); | ||
if (this.heartbeat) | ||
@@ -124,3 +125,3 @@ url.searchParams.append('heartbeat', this.heartbeat.toString()); | ||
if (!url) | ||
throw new Error("Invalid host address: " + address); | ||
throw new Error("Invalid host address: ".concat(address)); | ||
var name; | ||
@@ -144,3 +145,3 @@ var bindToQueue = false; | ||
default: | ||
throw new Error("Invalid protocol: " + url.protocol); | ||
throw new Error("Invalid protocol: ".concat(url.protocol)); | ||
} | ||
@@ -147,0 +148,0 @@ var settings = { name: name }; |
{ | ||
"name": "@maxjoehnk/masstransit-rabbitmq", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "MassTransit for JavaScript, RabbitMQ", | ||
@@ -5,0 +5,0 @@ "main": "dist/bus.js", |
108880
35
1986