Skip to content

Commit

Permalink
fix: operation bindings was looked for in message (#55)
Browse files Browse the repository at this point in the history
Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com>
  • Loading branch information
jonaslagoni and magicmatatjahu committed Mar 2, 2021
1 parent b343643 commit 16aed10
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions components/channel/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { realizeChannelName, camelCase, includeUnsubAfterForSubscription, messag
* @param {*} channelParameters parameters to the channel
* @param {*} params template parameters
*/
export function Reply(defaultContentType, channelName, replyMessage, receiveMessage, channelParameters, params) {
export function Reply(defaultContentType, channelName, replyMessage, receiveMessage, channelParameters, params, operation) {

//Create an array of all the parameter names
let parameters = [];
Expand Down Expand Up @@ -67,8 +67,8 @@ export function Reply(defaultContentType, channelName, replyMessage, receiveMess
try {
let subscribeOptions: SubscriptionOptions = {... options};
${includeQueueForSubscription(replyMessage)}
${includeUnsubAfterForSubscription(replyMessage)}
${includeQueueForSubscription(operation)}
${includeUnsubAfterForSubscription(operation)}
let subscription = await nc.subscribe(${realizeChannelName(channelParameters, channelName)}, ${shouldPromisifyCallbacks(params) ? 'async' : ''} (err, msg) => {
if (err) {
Expand Down
6 changes: 3 additions & 3 deletions components/channel/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { unwrap } from './ChannelParameterUnwrap';
* @param {*} message which is being received
* @param {*} channelParameters parameters to the channel
*/
export function Subscribe(defaultContentType, channelName, message, channelParameters) {
export function Subscribe(defaultContentType, channelName, message, channelParameters, operation) {

//Create an array of all the parameter names
let parameters = [];
Expand Down Expand Up @@ -46,8 +46,8 @@ export function Subscribe(defaultContentType, channelName, message, channelParam
): Promise<Subscription> {
return new Promise(async (resolve, reject) => {
let subscribeOptions: SubscriptionOptions = {... options};
${includeQueueForSubscription(message)}
${includeUnsubAfterForSubscription(message)}
${includeQueueForSubscription(operation)}
${includeUnsubAfterForSubscription(operation)}
try{
let subscription = await nc.subscribe(${realizeChannelName(channelParameters, channelName)}, (err, msg) => {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

9 changes: 6 additions & 3 deletions template/src/channels/$$channel$$.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { pascalCase, isRequestReply, isReplier, isRequester, isPubsub, messageHa
* @param {*} params
*/
function getChannelCode(asyncapi, channel, channelName, params) {
const publishMessage = channel.publish() ? channel.publish().message(0) : undefined;
const publishOperation = channel.publish() ? channel.publish() : undefined;
const publishMessage = publishOperation ? publishOperation.message(0) : undefined;
const subscribeMessage = channel.subscribe() ? channel.subscribe().message(0) : undefined;
let channelcode;
if (isRequestReply(channel)) {
Expand All @@ -35,7 +36,8 @@ function getChannelCode(asyncapi, channel, channelName, params) {
subscribeMessage,
publishMessage,
channel.parameters(),
params
params,
publishOperation
);
}
}
Expand All @@ -53,7 +55,8 @@ function getChannelCode(asyncapi, channel, channelName, params) {
asyncapi.defaultContentType(),
channelName,
publishMessage,
channel.parameters());
channel.parameters(),
publishOperation);
}
}
return channelcode;
Expand Down
16 changes: 8 additions & 8 deletions utils/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
/**
* Wrapper to include subscriptions option code if specified in the spec.
*
* @param {*} message to check for queue bindings on
* @param {*} operation to check for queue bindings on
*/
export function includeUnsubAfterForSubscription(message) {
if (message.hasBinding('nats') && message.bindings().nats.unsubAfter) {
return `subscribeOptions.max = '${message.binding('nats').unsubAfter}';`;
export function includeUnsubAfterForSubscription(operation) {
if (operation !== undefined && operation.hasBinding('nats') && operation.binding('nats').unsubAfter) {
return `subscribeOptions.max = '${operation.binding('nats').unsubAfter}';`;
}
return '';
}

/**
* Wrapper to include subscriptions queue option if specified in the spec.
*
* @param {*} message to check for queue bindings on
* @param {*} obj to check for queue bindings on
*/
export function includeQueueForSubscription(message) {
if (message.hasBinding('nats') && message.binding('nats').queue) {
return `subscribeOptions.queue = '${message.binding('nats').queue}';`;
export function includeQueueForSubscription(operation) {
if (operation !== undefined && operation.hasBinding('nats') && operation.binding('nats').queue) {
return `subscribeOptions.queue = '${operation.binding('nats').queue}';`;
}
return '';
}
Expand Down

0 comments on commit 16aed10

Please sign in to comment.