# messagingClient

### **Importing** <a href="#importing" id="importing"></a>

```typescript
import { messagingClient } from '@marblejs/messaging';
```

### **Type declaration**

```haskell
messagingClient :: MessagingClientConfig
    -> Reader<Context, Promise<MessagingClient>>
```

### **Parameters**

| *parameter* | definition              |
| ----------- | ----------------------- |
| *config*    | `MessagingClientConfig` |

#### ***MessagingClientConfig***

| ***parameter***  | definition                                                                                                                                       |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| *msgTransformer* | \<optional> `TransportMessageTransformer`                                                                                                        |
| *transport*      | `Transport` (see: [#createMicroservice](https://marblejs.gitbook.io/docs/other/api-reference/createmicroservice#createmicroserviceconfig))       |
| options          | `StrategyOptions` (see: [#createMicroservice](https://marblejs.gitbook.io/docs/other/api-reference/createmicroservice#createmicroserviceconfig)) |

{% hint style="warning" %}
Because of asynchronous nature of messaging client, all created readers have to be bound to server creators via eager binding 👉 [#bindEagerlyTo](https://marblejs.gitbook.io/docs/other/api-reference/core/bindeagerlyto)
{% endhint %}

To learn more about `messagingClient` output interface please visit:

{% content-ref url="../../../messaging/microservices" %}
[microservices](https://marblejs.gitbook.io/docs/messaging/microservices)
{% endcontent-ref %}

### Example (AMQP):

```typescript
import { bindEagerlyTo, createContextToken } from '@marblejs/core';
import { messagingClient, Transport } from '@marblejs/messaging';

const AmqpClientToken = createContextToken<MessagingClient>('AmqpClient');

const AmqpClient = messagingClient({
  transport: Transport.AMQP,
  options: {
    host: 'amqp://localhost:5672',
    queue: 'some_queue_name',
    queueOptions: { durable: false },
    timeout: 360 * 1000,
  },
});

...

const dependencies = [
  bindEagerlyTo(AmqpClientToken)(AmqpClient),
];

```

### Example (REDIS):

```typescript
import { bindEagerlyTo, createContextToken } from '@marblejs/core';
import { messagingClient, Transport } from '@marblejs/messaging';

const RedisClientToken = createContextToken<MessagingClient>('RedisClient');

const RedisClient = messagingClient({
  transport: Transport.REDIS,
  options: {
    host: 'redis://127.0.0.1:6379',
    channel: 'some_channel_name',
    timeout: 360 * 1000,
  },
});

...

const dependencies = [
  bindEagerlyTo(RedisClientToken)(RedisClient),
];

```
