# Code Samples

This section provides working code examples for connecting to the TRADE RabbitMQ feed in various programming languages.

## Available Samples

| Language                                                                   | File                  | Description                             |
| -------------------------------------------------------------------------- | --------------------- | --------------------------------------- |
| [C#](/u/trade/integration/code-samples/rmq-consumer-c.md)                  | .NET Core consumer    | Complete consumer with message handling |
| [Node.js](/u/trade/integration/code-samples/rmq-consumer-node.js.md)       | JavaScript/TypeScript | Event-based consumer using amqplib      |
| [Python](/u/trade/integration/code-samples/rmq-consumer-python.md)         | Python 3.x            | Consumer using pika library             |
| [PHP](/u/trade/integration/code-samples/rmq-consumer-php.md)               | PHP 7.4+              | Consumer using php-amqplib              |
| [GO](/u/trade/integration/code-samples/rmq-consumer-go.md)                 | Golang                | Consumer using streadway/amqp           |
| [JavaScript](/u/trade/integration/code-samples/rmq-consumer-javascript.md) | Browser/Node          | Basic JavaScript implementation         |

## Prerequisites

Before running any code sample, ensure you have:

1. **Valid credentials** — Username, password, and Package ID provided by your CSM
2. **Enabled distribution** — Call the Distribution/Start API endpoint
3. **Network access** — Ability to reach the InPlay and PreMatch RMQ hosts listed below

## Common Configuration

Connect using the username and password provided by your CSM. The host and virtual host depend on the feed type:

| Parameter        | InPlay                  | PreMatch                  |
| ---------------- | ----------------------- | ------------------------- |
| **Host**         | `stm-inplay.lsports.eu` | `stm-prematch.lsports.eu` |
| **Virtual Host** | `StmInPlay`             | `StmPreMatch`             |

| Parameter    | Value                                 |
| ------------ | ------------------------------------- |
| **Port**     | `5672`                                |
| **Queue**    | `_YOUR_PACKAGE_ID_` (e.g. `_102030_`) |
| **Protocol** | AMQP 0.9.1                            |

## Message Flow

```
┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│   TRADE Feed    │────▶│    RabbitMQ     │────▶│  Your Consumer  │
└─────────────────┘     └─────────────────┘     └─────────────────┘
                              │
                              ▼
                        Your Queue
                       _PACKAGE_ID_
```

## Best Practices

1. **Enable automatic recovery** - Handle connection drops gracefully
2. **Process messages asynchronously** - Don't block the message loop
3. **Implement proper logging** - Track message flow and errors
4. **Monitor heartbeats** - Detect feed issues early
5. **Use prefetch** - Control message buffer size

## Need Help?

If you need a code sample for a language not listed here, contact our support team.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lsports.eu/u/trade/integration/code-samples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
