Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expose enabled use attributes feature for server #24

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/gc-pubsub.client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ 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 @@ -355,6 +356,7 @@ 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
2 changes: 2 additions & 0 deletions lib/gc-pubsub.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class GCPubSubClient extends ClientProxy {
json: serializedPacket.data,
attributes: {
pattern: serializedPacket.pattern,
useAttributes: 'true',
},
});
} else {
Expand All @@ -206,6 +207,7 @@ export class GCPubSubClient extends ClientProxy {
replyTo: this.replyTopicName,
pattern: serializedPacket.pattern,
id: serializedPacket.id,
useAttributes: 'true',
},
})
.catch((err) => callback({ err }));
Expand Down
9 changes: 8 additions & 1 deletion lib/gc-pubsub.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ export class GCPubSubServer extends Server implements CustomTransportStrategy {
: JSON.stringify(packet.pattern);

const context = new GCPubSubContext([message, pattern]);
const correlationId = packet.id || attributes.id;

let correlationId: string;

if (attributes.useAttibutes === 'true') {
correlationId = attributes.id;
} else {
correlationId = packet.id;
}

if (isUndefined(correlationId)) {
return this.handleEvent(pattern, packet, context);
Expand Down
9 changes: 6 additions & 3 deletions tests/src/gc-pubsub.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ export class GCPubSubController implements OnApplicationShutdown {

@Post('notify')
async sendNotification(): Promise<any> {
return this.client.emit<number>('notification', true);
return this.client.emit<{ notification: boolean; id: string }>(
'notification',
{ notification: true, id: 'id' },
);
}

@EventPattern('notification')
eventHandler(data: boolean) {
GCPubSubController.IS_NOTIFIED = data;
eventHandler(data: { notification: boolean; id: string }) {
GCPubSubController.IS_NOTIFIED = data.notification;
}
}