This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const gateway = require('fastify')({}) | |
| gateway.register(require('fastify-reply-from')) | |
| gateway.register(require('k-fastify-gateway'), { | |
| middlewares: [ | |
| require('cors')(), // https://www.npmjs.com/package/cors | |
| require('helmet')() // https://helmetjs.github.io/ | |
| ], | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { ServiceBroker } = require("./../index"); | |
| let broker = new ServiceBroker({ | |
| logger: true, | |
| transporter: { | |
| type: "hazelcast", | |
| options: { | |
| init(cfg) { | |
| cfg.properties["hazelcast.logging"] = "off"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Get a distributed lock called "my-distributed-lock" | |
| ILock lock = hz.getILock("my-distributed-lock"); | |
| // Now create a lock and execute some guarded code. | |
| lock.lock(); | |
| try { | |
| //do something here | |
| } catch (...) { | |
| lock.unlock(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // on application instance start, init near cache Map | |
| const {Client, Config} = require('hazelcast-client') | |
| const nearCachedMapName = 'my-holy-fast-map' | |
| const cfg = new Config.NearCacheConfig() | |
| cfg.name = nearCachedMapName | |
| cfg.invalidateOnChange = true | |
| cfg.nearCacheConfigs[nearCachedMapName] = cfg | |
| const hazelcast = await Client.newHazelcastClient(cfg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const lock = hazelcast.getLock('my-distributed-lock') | |
| lock.lock().then(() => { | |
| // the execution of this function will happen once | |
| // at a time across all distributed instances | |
| // ... | |
| console.log('Happy Locking!') | |
| }).finally(() => lock.unlock()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // on application instance start... | |
| const counter = hazelcast.getAtomicLong('distributed-pushes-counter') | |
| await counter.compareAndSet(0, await PushLogs.count({})) | |
| // on push... | |
| await counter.incrementAndGet() | |
| // on request | |
| await counter.get() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (async () => { | |
| const Client = require('hazelcast-client').Client | |
| const hz = await Client.newHazelcastClient() | |
| const list = hz.getList('my-distributed-list') | |
| await list.add(process.pid) | |
| console.log(await list.toArray()) | |
| await hz.shutdown() | |
| })() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const server = require('express')({}) | |
| server.get('/', (req, res) => { | |
| res.send('Hello World!') | |
| }) | |
| server.listen(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express') | |
| const bodyParser = require('body-parser') | |
| const axios = require('axios') | |
| const httpc = axios.create({ | |
| baseURL: 'http://localhost:3000', | |
| timeout: 30000 | |
| }) | |
| const app = express() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const N = 2000000 | |
| const items = [] | |
| for (var i = 0; i < N; i++) { | |
| items.push({ index: i }) | |
| } | |
| console.log(items.map(e => e.index).filter(v => v % 2 === 0).reduce((sum, v) => sum += v)) |