Xcom::sendAsync

Send a message asynchronously

&reftitle.description; public `int` `Xcom::sendAsync` `string` `topic` `mixed` `data` `string` `json_schema` `array` `http_headers`

Send a message to a capability (API provider) for a topic asynchronously (using pthreads).

&reftitle.parameters;

If `json_schema` is specified, the `data` must be an object and is encoded as an avro-encoded message.

If `json_schema` is not specified, the `data` will be converted to a string and sent.

`topic`

- The topic path (ie, /store/get/orders).

`data`

- The data to be sent.

`json_schema`

- The avro JSON schema if `data` is an object, if left empty there is no avro encoding.

`http_headers`

- HTTP client headers (such as User-Agent, Accept, etc.)

&reftitle.returnvalues;

Returns `0`.

&reftitle.examples;

### `Xcom::sendAsync` example (avro)

    <?php
    $schema = file_get_contents('http://api.x.com/ocl/com.x.example.v1/OrderFulfillment/OrderShipped/1.2.0/');

    $data = new stdClass();
    $data->orderID = "123495585343";

    $xcom = new Xcom(XCOM_FABRIC_SANDBOX, "fabric_token", "capability_token");

    $xcom->sendAsync("/com.x.example.v1/OrderFulfillment/OrderShipped", $data, $schema);
    ?>

### `Xcom::sendAsync` example (arbitrary payload)

    <?php

    $xcom = new Xcom(XCOM_FABRIC_PRODUCTION, "fabric_token", "capability_token");

    $xcom->sendAsync("/get/profile", 'request-payload');
    ?>

&reftitle.seealso;

- `Xcom::send`