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

feat: pubsub mvp #347

Merged
merged 19 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
81 changes: 5 additions & 76 deletions examples/package-lock.json

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

4 changes: 3 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"advanced": "tsc && node dist/advanced.js",
"load-gen": "tsc && node dist/load-gen.js",
"dictionary": "tsc && node dist/dictionary.js",
"topic-publish": "tsc && node dist/topic-publish.js",
"topic-subscribe": "tsc && node dist/topic-subscribe.js",
"test": "jest",
"lint": "eslint . --ext .ts",
"format": "eslint . --ext .ts --fix"
Expand All @@ -31,7 +33,7 @@
},
"dependencies": {
"@gomomento/generated-types": "0.32.1",
"@gomomento/sdk": "1.4.0",
"@gomomento/sdk": "../dist/src",
"@grpc/grpc-js": "1.7.3",
"hdr-histogram-js": "3.0.0",
"node-fetch": "2.6.7",
Expand Down
42 changes: 42 additions & 0 deletions examples/topic-publish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
TopicClient,
TopicPublish,
Configurations,
CredentialProvider,
} from '@gomomento/sdk';

async function main() {
const clargs = process.argv.slice(2);
if (clargs.length !== 3) {
console.error('Usage: topic-publish.ts <cacheName> <topicName> <value>');
return;
}
const cacheName = clargs[0];
const topicName = clargs[1];
const value = clargs[2];
const momento = new TopicClient({
configuration: Configurations.Laptop.v1(),
credentialProvider: CredentialProvider.fromEnvironmentVariable({
environmentVariableName: 'TEST_AUTH_TOKEN',
}),
});

console.log(
`Publishing cacheName=${cacheName}, topicName=${topicName}, value=${value}`
);
const publishResponse = await momento.publish(cacheName, topicName, value);
if (publishResponse instanceof TopicPublish.Success) {
console.log('Value published successfully!');
} else {
console.log(`Error publishing value: ${publishResponse.toString()}`);
}
}

main()
.then(() => {
console.log('success!!');
})
.catch((e: Error) => {
console.error(`An error occurred! ${e.message}`);
throw e;
});
45 changes: 45 additions & 0 deletions examples/topic-subscribe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
TopicClient,
TopicSubscribe,
Configurations,
CredentialProvider,
} from '@gomomento/sdk';

async function main() {
const clargs = process.argv.slice(2);
if (clargs.length !== 2) {
console.error('Usage: topic-subscribe.ts <cacheName> <topicName>');
return;
}
const cacheName = clargs[0];
const topicName = clargs[1];
const momento = new TopicClient({
configuration: Configurations.Laptop.v1(),
credentialProvider: CredentialProvider.fromEnvironmentVariable({
environmentVariableName: 'TEST_AUTH_TOKEN',
}),
});

console.log(`Subscribing to cacheName=${cacheName}, topicName=${topicName}`);
await momento.subscribe(cacheName, topicName, {
dataListener: handleData,
errorListener: handleError,
malandis marked this conversation as resolved.
Show resolved Hide resolved
});
}

function handleData(data: TopicSubscribe.Item) {
console.log('Data received from subscription stream; %s', data);
}

function handleError(error: TopicSubscribe.Error) {
console.log(`Error received from subscription stream; ${error.toString()}`);
malandis marked this conversation as resolved.
Show resolved Hide resolved
}

main()
.then(() => {
console.log('success!!');
})
.catch((e: Error) => {
console.error(`An error occurred! ${e.message}`);
throw e;
});
malandis marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"uuid": "8.3.2"
},
"dependencies": {
"@gomomento/generated-types": "0.50.0",
"@gomomento/generated-types": "0.51.1",
"@grpc/grpc-js": "1.7.3",
"google-protobuf": "^3.21.2",
"jwt-decode": "3.1.2"
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {CacheClient, SimpleCacheClient} from './cache-client';
import {TopicClient} from './topic-client';
import * as Configurations from './config/configurations';
import * as CacheGet from './messages/responses/cache-get';
import * as CacheListConcatenateBack from './messages/responses/cache-list-concatenate-back';
Expand Down Expand Up @@ -44,6 +45,8 @@ import * as CacheSortedSetGetScores from './messages/responses/cache-sorted-set-
import * as CacheSortedSetIncrementScore from './messages/responses/cache-sorted-set-increment-score';
import * as CacheSortedSetRemoveElement from './messages/responses/cache-sorted-set-remove-element';
import * as CacheSortedSetRemoveElements from './messages/responses/cache-sorted-set-remove-elements';
import * as TopicPublish from './messages/responses/topic-publish';
import * as TopicSubscribe from './messages/responses/topic-subscribe';

import {CacheInfo} from './messages/cache-info';
import {CollectionTtl} from './utils/collection-ttl';
Expand Down Expand Up @@ -143,6 +146,9 @@ export {
CacheSortedSetIncrementScore,
CacheSortedSetRemoveElement,
CacheSortedSetRemoveElements,
TopicClient,
TopicPublish,
TopicSubscribe,
MomentoErrorCode,
AlreadyExistsError,
AuthenticationError,
Expand Down
Loading