Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix: Remove hard-coded /user prefix for broker queues (#56)
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Kim <[email protected]>
  • Loading branch information
jooskim committed Aug 25, 2021
1 parent a49ff42 commit fb990d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
12 changes: 5 additions & 7 deletions src/bridge/broker-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class BrokerConnector implements EventBusEnabled {
const subscriptionId = this.generateSubscriptionId(session.id, cleanedChannel);
const brokerPrefix = galacticConfig.isPrivate ? config.queueLocation : config.topicLocation;
const destination =
StompParser.generateGalacticDesintation(brokerPrefix, cleanedChannel, galacticConfig.isPrivate);
StompParser.generateGalacticDesintation(brokerPrefix, cleanedChannel);
const subscription =
StompParser.generateStompBrokerSubscriptionRequest(
session.id, destination, subscriptionId, galacticConfig.isPrivate, brokerPrefix
Expand Down Expand Up @@ -358,7 +358,7 @@ export class BrokerConnector implements EventBusEnabled {
const brokerPrefix = this._privateChannels.get(channel)[sessionBrokerIdentity] ?
config.queueLocation : config.topicLocation;
const destination =
StompParser.generateGalacticDesintation(brokerPrefix, cleanedChannel, isPrivateChannel);
StompParser.generateGalacticDesintation(brokerPrefix, cleanedChannel);
const subscription = StompParser.generateStompBrokerSubscriptionRequest(
session.id, destination, subscriptionId, isPrivateChannel, brokerPrefix);

Expand Down Expand Up @@ -741,7 +741,7 @@ export class BrokerConnector implements EventBusEnabled {
);

const channel: string = StompParser.convertTopicOrQueueToChannel(
data.destination, data.brokerPrefix, data.isQueue);
data.destination, data.brokerPrefix);

const chan: Observable<Message> =
this.bus.api.getRequestChannel(channel, this.getName());
Expand All @@ -764,8 +764,7 @@ export class BrokerConnector implements EventBusEnabled {
let respChan =
StompParser.convertSubscriptionToChannel(
data.destination,
data.isQueue ? session.config.queueLocation : session.config.topicLocation,
data.isQueue);
data.isQueue ? session.config.queueLocation : session.config.topicLocation);
let payload = JSON.parse(msg.body);

const respChannelObject = this.bus.api.getChannelObject(respChan);
Expand Down Expand Up @@ -820,8 +819,7 @@ export class BrokerConnector implements EventBusEnabled {

// let the bus know.
this.sendBusCommandResponseRaw(message, BrokerConnectorChannel.subscription, true);
const channel: string = StompParser.convertTopicOrQueueToChannel(
data.destination, data.brokerPrefix, data.isQueue);
const channel: string = StompParser.convertTopicOrQueueToChannel(data.destination, data.brokerPrefix);

const sub: Subscription = session.getGalacticSubscription(channel);

Expand Down
4 changes: 2 additions & 2 deletions src/bridge/stomp.parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ describe('Stomp Parser [stomp.parser]', () => {

// public channel
const subA = StompParser.convertSubscriptionToChannel(
'puppykitty/', 'kitty', false);
'puppykitty/', 'kitty');
expect(subA).toEqual('puppy');

// private channel
const subB = StompParser.convertSubscriptionToChannel(
'/userpuppy/kitty', 'puppy', true);
'puppy/kitty', 'puppy');
expect(subB).toEqual('kitty');

}
Expand Down
14 changes: 6 additions & 8 deletions src/bridge/stomp.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,22 @@ export class StompParser {
}

// create galactic topic/queue detination
public static generateGalacticDesintation(dest: string, channel: string, isQueue: boolean): string {
return (isQueue ? '/user' : '') + dest + '/' + channel;
public static generateGalacticDesintation(dest: string, channel: string): string {
return dest + '/' + channel;
}

// convert destination back into a channel
public static convertSubscriptionToChannel(subscription: string,
topicOrQueueDesintation: string,
isQueue: boolean): string {
topicOrQueueDesintation: string): string {
return subscription.replace(
(isQueue ? '/user' + topicOrQueueDesintation : topicOrQueueDesintation) + '/',
topicOrQueueDesintation + '/',
'');
}

// convert topic/queue back into a channel
public static convertTopicOrQueueToChannel(subscription: string,
brokerPrefix: string,
isQueue: boolean): string {
brokerPrefix: string): string {
return subscription.replace(
isQueue ? '/user' + brokerPrefix + '/' : brokerPrefix + '/', '').trim();
brokerPrefix + '/', '').trim();
}
}

0 comments on commit fb990d8

Please sign in to comment.