How to use the rhea.rpc_server function in rhea

To help you get started, we’ve selected a few rhea examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github amqp / rhea / examples / rpc / server.js View on Github external
* See the License for the specific language governing permissions and
 * limitations under the License.
 */
var container = require('rhea');

var cache = [0, 1];
function fib(n) {
    if (n >= cache.length) {
        for(var i = 2; i <= n; i++) {
            cache[i] = cache[i-2] + cache[i-1];
        }
    }
    return cache[n];
}

var server = container.rpc_server('amqp://localhost:5672/examples');

server.bind_sync(fib);

var map = {};
function put(args, callback) {
    map[args.key] = args.value;
    callback();
}

function get(key, callback) {
    callback(map[key]);
}

server.bind(put);
server.bind(get);