BlockchainMQ
Usage xample
Using with mocks
const keySource = new MockKeySource();
const dataSource = new MockDataSource<string>();
const bmq = new BlockchainMQ({
keySource,
dataSource,
ownKey: await keySource.getMyKey('my_org_id'),
pollingInterval: 1000,
});
const topic = 56;
const emitter = await bmq.poll<string>(topic);
let lastCursor;
emitter.on('message', (message) => {
console.log(message);
});
emitter.on('newCursor', (cursor) => {
lastCursor = cursor;
});
await bmq.send<string>(
topic,
'Hello!',
'some_receiver_org_id',
);
await bmq.send<string>(
topic,
'Hello!'
);
emitter.stop();
bmq.stopAll();
Using with EOS blockchain
To use with the real blockchain, create client instance as follows (also look at blockchainMQ.e2e-spec.ts for example):
import { AggregionBlockchain } from '@aggregion/dmp-contracts';
const client = new AggregionBlockchain(nodeUrl, [
pair1.privateKey,
pair2.privateKey,
]);
const blockchainMQ = new BlockchainMQ({
keySource: new EosKeySource({
contractName: 'dmpusers',
client: client,
}),
dataSource: new EosDataSource({
contractName: 'dmpusers',
client: client,
clientAccount: 'your_orgId',
}),
ownKey: {
orgId: 'your_orgId',
data: 'your organization private key',
format: KeyFormat.PKCS1_PEM,
algo: KeyAlgo.RSA_4096,
},
pollingInterval: 500,
});