@avassa/client
v0.2.4
Published
Avassa client
Readme
Avassa client
A library for integrating with the Avassa APIs.
For usage see example and tests.
See CHANGELOG for changes.
Login
const creds = approle_credentials(secret_id, role_id);
const client = await login(ct, creds);Open a Consumer
const opts: OpenConsumer = {
topic: topic,
name: "test-consumer",
mode: Mode.Exclusive,
location: Location.ChildSite,
"child-site": site,
position: Position.Unread,
"on-no-exists": OnNoExists.Fail,
};
const consumer = client.open_volga_consumer(opts);
consumer.onError = ((e: Error) => { console.log(`${e}`) });
consumer.onConnect = () => { console.log("connected") };
consumer.onMessage = msg => {
console.log(`Got message: ${JSON.stringify(msg)}`);
// Ack the message
consumer.ack(msg.seqno);
};
consumer.connect();
...
consumer.close();Open a Producer
const opts: OpenProducer = {
topic: "test-topic",
name: "test-producer",
"on-no-exists": OnNoExists.Create,
"create-options": {
"replication-factor": 1,
persistence: Persistence.Disk,
format: Format.String,
},
};
const producer = client.open_volga_producer(opts);
await new Promise<void>((resolve, reject) => {
producer.onError = (e: Error) => { reject(e); };
producer.onConnect = () => {
resolve();
};
producer.connect();
});
await new Promise<void>((resolve, reject) => {
producer.onError = (e: Error) => { reject(e); };
producer.onProduce = () => {
resolve();
};
producer.produce("test-message");
});
producer.close();Running the tests
Since the tests will try to connect to a real Control Tower (or Edge Enforce), create
.jest/setEnvVars.js
process.env.CONTROL_TOWER="https://api.x.y.avassa.net"
process.env.CT_USERNAME="[email protected]"
process.env.CT_PASSWORD="secret-password"
