> For the complete documentation index, see [llms.txt](https://rxjs.gitbook.io/rx-txjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rxjs.gitbook.io/rx-txjs/how-to-use-it/c2c-component-2-component-communication.md).

# C2C

### Component-2-Component Communication

This feature enable you to set a direct communication channels between components. This save you from the hassle of configure the I/S just to transfer data between components. There are two types of data transports the library support *'message queue'* and *'node express'*.

The classes involving the C2C:

* **TxQueuePoint** - an object able to connect, send and receive data from other end-point components. It has internally an object implement TxConnector interface. the TxConnector define three methods *connect*, *next*and *subscribe*. The TxConnector implement the underline detail of your transport details. The class implement TxConnector, whether it is default TxConnectorRabbitMQ or your implementation, is injected into TxQueuePoint during creation.

> To use your implementation of TxConnector you need to register it on the TxQueuePointRegistry using setDriver method.

* **TxRoutePoint** - work the same as TxQueuePoint but iot use node express as the underline communication I/S.

> To use your implementation of TxConnector you need to register it on the TxRoutePointRegistry using setDriver method.

* **TxQueuePointRegistry** - an object able to create, store and retrieve TxQueuePoint objects. Use the method TxQueuePointRegistry.setDriver to register your driver (class that implement TxConnector).
* **TxRoutePointRegistry** - an object able to create, store and retrieve TxRoutePoint objects. Use the method TxQueuePointRegistry.setDriver to register your driver (class that implement TxConnector).

#### How It Work

* **set you driver** - first you need to define a connector driver. a driver is an object implement **`TxConnector`**&#x69;nterface.

> **NOTE:** if you are using RabbitMQ message queue then you can use the builtin support for RabbitMQ, so safly you can skip the driver stuff.

> See the builtin TxConnectorRabbitMQ for an example.

```
 export interface TxConnector {  subscribe: (any) => void;   connect(service, route);  next(service: string, route: string, data: any);  close();} 
```

The driver is one for all components. API is as follow:

1. **subscribe** - a registration callback method where you will get the data.
2. **next** - sending data to other service on a service/route.
3. **connect** - set the connection. In the case RabbitMQ is set the exchange/queue/binding. This way other components may recognaize you.

Once your driver is working you need to register it into TxQeuePointRegistry as:

```
TxQueuePointRegistry.instance.setDriver(YourClass); // for exampleclass MyConnector implements TxConnector {  ...}TxQueuePointRegistry.instance.setDriver(MyConnector);
```

* **use subscribe / next** - now you can define your connector (or use the builtin RabbitMQ connector) to define subscribe and next methods to receive and send data.

See the following example:

```
export class Q1Component {  // get a queue point from the registry. please note we are using queue driver.  queuepoint: TxQueuePoint = TxQueuePointRegistry.instance.queue('GITHUB::API::AUTH');   constructor() {  }   async init() {    // call to connect one time. this call the connect method on the connector you defined earlier (or use the builtin).    routepoint    await this.queuepoint.queue().connect('service-1.queuepoint', 'Q1Component.tasks');     // incoming data from other components are received here using the subscribe method.     await this.queuepoint.queue().subscribe(      async (data) => {        console.log("[Q1Component:subscribe] got data = " + data);         // sending reply back to sender.         await this.queuepoint.queue().next('service-2.queuepoint', 'Q2Component.tasks', {from: 'service-1.queuepoint', data: 'data'});      });     return this;  }}
```

###
