Skip to content

Commit

Permalink
Merge pull request #25 from p-fedyukovich/feature/remove-use-attribut…
Browse files Browse the repository at this point in the history
…es-from-message

feat: remove use attributes message attr
  • Loading branch information
p-fedyukovich authored Apr 28, 2023
2 parents f4945f8 + 7dce1c0 commit d964e39
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/gc-pubsub.client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ describe('GCPubSubClient', () => {
expect(message.json).to.be.eql(msg.data);
expect(message.attributes.pattern).to.be.eql(pattern);
expect(message.attributes.id).to.be.not.empty;
expect(message.attributes.useAttributes).to.be.eql('true');
});
});
});
Expand Down Expand Up @@ -356,7 +355,6 @@ describe('GCPubSubClient', () => {
const message = topicMock.publishMessage.getCall(0).args[0];
expect(message.json).to.be.eql(msg.data);
expect(message.attributes.pattern).to.be.eql(msg.pattern);
expect(message.attributes.useAttributes).to.be.eql('true');
});

it('should throw error', async () => {
Expand Down
4 changes: 1 addition & 3 deletions lib/gc-pubsub.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export class GCPubSubClient extends ClientProxy {
json: serializedPacket.data,
attributes: {
pattern: serializedPacket.pattern,
useAttributes: 'true',
},
});
} else {
Expand All @@ -207,7 +206,6 @@ export class GCPubSubClient extends ClientProxy {
replyTo: this.replyTopicName,
pattern: serializedPacket.pattern,
id: serializedPacket.id,
useAttributes: 'true',
},
})
.catch((err) => callback({ err }));
Expand Down Expand Up @@ -239,7 +237,7 @@ export class GCPubSubClient extends ClientProxy {
rawMessage,
) as IncomingResponse;

const correlationId = id || message.attributes.id;
const correlationId = message.attributes.id || id;

const callback = this.routingMap.get(correlationId);
if (!callback) {
Expand Down
4 changes: 3 additions & 1 deletion lib/gc-pubsub.server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ describe('GCPubSubServer', () => {
ackId: 'id',
// @ts-ignore
publishTime: new Date(),
attributes: {},
attributes: {
replyTo: 'replyTo',
},
id: 'id',
received: 0,
deliveryAttempt: 1,
Expand Down
6 changes: 5 additions & 1 deletion lib/gc-pubsub.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class GCPubSubServer extends Server implements CustomTransportStrategy {
const rawMessage = JSON.parse(data.toString());

let packet;
if (attributes.useAttributes === 'true') {
if (attributes.pattern) {
packet = this.deserializer.deserialize({
data: rawMessage,
id: attributes.id,
Expand All @@ -167,6 +167,10 @@ export class GCPubSubServer extends Server implements CustomTransportStrategy {
const handler = this.getHandlerByPattern(pattern);

if (!handler) {
if (!attributes.replyTo) {
return;
}

const status = 'error';
const noHandlerPacket = {
id: correlationId,
Expand Down

0 comments on commit d964e39

Please sign in to comment.