Skip to content

Variable: buildHTTPServiceProxy ​

说明

本页由源码中的注释生成,内容为英文。

const buildHTTPServiceProxy: ComponentOptionsBuilder<BuildHTTPServiceProxyOptions>

Build the component options of an HTTPServiceProxy, to register it in the components of an application.

Param ​

options

The service's address, and the headers, client id and reconnection delay.

Returns ​

The component options.

Example ​

typescript
import {Application} from 'lakutata'
import {buildHTTPServiceProxy, type HTTPServiceProxy} from 'lakutata/com/entrypoint'

Application
    .run(() => ({
        id: 'shop.app',
        name: 'Shop',
        components: {
            inventory: buildHTTPServiceProxy({url: 'http://inventory.internal:3000/'}),
            //With a token, and a stable client id to receive the events of the service
            orders: buildHTTPServiceProxy({
                url: 'https://orders.internal/rpc',
                headers: {Authorization: `Bearer ${process.env.ORDERS_TOKEN}`},
                clientId: 'shop-1'
            })
        }
    }))
    .onLaunched(async (app: Application): Promise<void> => {
        const inventory: HTTPServiceProxy = await app.getObject<HTTPServiceProxy>('inventory')
        console.log(await inventory.invoke({cmd: 'stock.get', product: 'lamp'}))
    })

Released under the MIT License.