PHP code example of synapse-rpc / siroen

1. Go to this page and download the library: Download synapse-rpc/siroen library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

synapse-rpc / siroen example snippets


    use Synapse\Synapse;
    
    $ec = function ($msg, $raw) {
        printf("收到信息: %s\n", $raw->body);
        return true;
    };
    $events = [
        'dotNet.test' => $ec,
        'golang.test' => $ec,
        'python.test' => $ec
    ];
    
    $rpcs = [
        'test' => function ($msg, $raw) {
            printf("收到RPC: %s\n", $raw->body);
            return [
                'from' => 'php',
                'm' => $msg['msg'],
                'number' => 5233
            ];
        }
    ];
    
    $app = new Synapse();
    $app->sys_name = 'simcu';
    $app->app_name = 'php';
    $app->mq_host = 'xxx';
    $app->mq_user = 'xxx';
    $app->mq_pass = 'xxx';
    $app->debug = true;
    $app->rpc_callback = $rpcs;
    $app->event_callback = $events;
    //$app->disable_rpc_client = true;
    //$app->disable_event_client = true;
    $app->serve();

/**
 * 事件回调
 * @param array $msg 收到的信息数组
 * @param object $raw libamqp原始信息
 * @return bool 回复true表示确认信息,false将会将消息送回队列
 */
function eventCallback($msg, $raw)
{
    return true;
}

/**
 * RPC回调
 * @param array $msg 收到的信息数组
 * @param object $raw libamqp原始信息
 * @return array 必须是键值对数组,将会序列为json
 */
function rpcCallback($msg, $raw)
{
    return [];
}