Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active November 30, 2023 21:11
Show Gist options
  • Select an option

  • Save wilmoore/ae8de4239b7c2726d7478f55cbe2cc95 to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/ae8de4239b7c2726d7478f55cbe2cc95 to your computer and use it in GitHub Desktop.
Income Sources :: Jobs :: 2022 :: HP :: Lens :: Repos :: poly-glass :: team-mo :: match-maker :: Messaging Client

Income Sources :: Jobs :: 2022 :: HP :: Lens :: Repos :: poly-glass :: team-mo :: match-maker :: Messaging Client

⪼ Made with 💜 by realpolyglot.com

Adding Relationships

Yes, we do this via @poly/messaging-client that abstracts away rabbit and the queues.

We have a couple of different ways of intracting with servcies via the messaging-client. Some of them expose client SDKs that completely remove the need to use the messaging-client directly, some don't, let me familarize myself with match-makers interfaces quickly and I'll show you how to send a message to add a releationship.

device.info.update (endpoint)

Actually, device.info.state

Ah, must have gotten side-traced, there are certainly no SDKs for match-maker. I think the best option here will be to send a device.info.update message which has a schema to communicate creating, updating or removing relationships between entitites (devices or users)


import "./env";
import { MessagingAPI, Address, Action } from "@poly/messaging-client";
import { EntityType, RelationshipType } from "./types";
const messagingClient = MessagingAPI.getMessagePublisher();
const resourceAddress = Address.ForResource('match-maker');
// NOTE: every time we send these, the IDs should be new because the relationships are meant to be immutable
// TODO: pass in from environment or command-line args
const deviceId = '948017ED-CE27-4EBF-A2C1-D8972548E22E';
// TODO: pass in from environment or command-line args
const userId = 'EB8BB32F-82A2-4E15-91D5-D87D02DA1640';
async function main() {
const entities = [
{
deviceid: deviceId,
connections: [
{
from: deviceId,
to: userId,
targetEntityType: EntityType.User,
connected: true,
type: RelationshipType.External,
},
],
},
];
const response: any = await messagingClient.sendEvent(resourceAddress, Action.Build(1, 'device', 'info', 'state'), {
id: deviceId,
body: { entities },
});
console.dir(response);
MessagingAPI.disconnectAllReceivers();
}
main();
import "./env";
import { MessagingAPI, Address, Action } from "@poly/messaging-client";
import { Message, RelationshipOptions, RelationshipType, } from "./types";
const messagingClient = MessagingAPI.getMessagePublisher();
const resourceAddress = Address.ForResource('match-maker');
// NOTE: the `id` value should match the value of `deviceId` in the `device-info-state.ts` file
// TODO: pass in from environment or command-line args
const id = '948017ED-CE27-4EBF-A2C1-D8972548E22E';
async function main() {
const options: RelationshipOptions = {
// relation: RelationshipType.External,
}
const response: Message = await messagingClient.sendRequest(resourceAddress, Action.Build(1, 'get', 'entity', 'relationships'), {
id,
options,
});
console.dir(response?.body?.data);
MessagingAPI.disconnectAllReceivers();
}
main();
export type Message = {
body?: { data?: any[] }
};
export enum EntityType {
Application = "application",
Device = "device",
User = "user",
Adapter = "adapter",
VirtualDevice = "virtual-device"
}
export enum RelationshipType {
Generic = 'generic',
Auth = 'auth',
Peer = 'peer',
External = 'external',
Proxy = 'proxy',
Container = 'container',
Temporary = 'temporary',
/** @deprecated */
Via = 'via'
}
export type RelationshipFetchOptions = {
includeRelations?: Array<RelationshipType>;
excludeRelations?: Array<RelationshipType>;
isActive?: boolean;
};
export type RelationshipOptions = {
entityType?: EntityType | Array<EntityType>;
relation?: RelationshipType;
directOnly?: boolean;
active?: boolean;
} & RelationshipFetchOptions;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment