# Events Publishers

Source: https://docs.formance.com/v3.2/modules/ledger/advanced/events-publishers

Stack: v3.2

## Events

The following event types are available:

| Event                   | Description                                                               |
| ----------------------- | ------------------------------------------------------------------------- |
| SET\_METADATA           | Log entry for setting metadata on an account or transaction               |
| NEW\_TRANSACTION        | Log entry for creating a new transaction with associated account metadata |
| REVERTED\_TRANSACTION   | Log entry for reverting an existing transaction                           |
| DELETE\_METADATA        | Log entry for deleting metadata from an account or transaction            |
| INSERTED\_SCHEMA        | Log entry for inserting a new ledger schema                               |
| COMMITTED\_TRANSACTIONS | External event published when transactions are committed to the ledger    |
| SAVED\_METADATA         | External event published when metadata is saved on an entity              |
| DELETED\_METADATA       | External event published when metadata is deleted from an entity          |

## Publishing to HTTP

An HTTP publisher is available out of the box since 1.3. It allows you to push ledger events to an HTTP server of your choice, in a webhook-like fashion. It can be enabled by setting the
[configuration variables](https://docs.formance.com/deploy/self-hosted/config/settings) `PUBLISHER_HTTP_ENABLED` and `PUBLISHER_TOPIC_MAPPING`.

Applies to: deployment=cloud.

For HTTP publishing on Formance Cloud, refer to the [Webhooks module](https://docs.formance.com/v3.2/modules/webhooks).

The event payload is formatted as follows:

A COMMITTED\_TRANSACTIONS event published when new transactions are committed to a ledger. Contains the complete transaction data including postings, volumes, and associated account metadata.

```json
{
  "date": "2024-01-15T10:30:00Z",
  "app": "ledger",
  "version": "v2",
  "type": "COMMITTED_TRANSACTIONS",
  "payload": {
    "ledger": "quickstart",
    "transactions": [
      {
        "id": 1,
        "postings": [
          {
            "source": "world",
            "destination": "users:001",
            "amount": "100",
            "asset": "USD"
          },
          {
            "source": "users:001",
            "destination": "payments:001",
            "amount": "100",
            "asset": "USD"
          }
        ],
        "metadata": {
          "category": "payment",
          "reference": "tx_001"
        },
        "timestamp": "2024-01-15T10:30:00Z",
        "insertedAt": "2024-01-15T10:30:01Z",
        "updatedAt": "2024-01-15T10:30:01Z",
        "reference": "payment_001",
        "postCommitVolumes": {
          "users:001": {
            "USD": {
              "input": "100",
              "output": "100",
              "balance": "0"
            }
          },
          "payments:001": {
            "USD": {
              "input": "100",
              "output": "0",
              "balance": "100"
            }
          },
          "world": {
            "USD": {
              "input": "0",
              "output": "100",
              "balance": "-100"
            }
          }
        },
        "preCommitVolumes": {
          "users:001": {
            "USD": {
              "input": "0",
              "output": "0",
              "balance": "0"
            }
          },
          "payments:001": {
            "USD": {
              "input": "0",
              "output": "0",
              "balance": "0"
            }
          },
          "world": {
            "USD": {
              "input": "0",
              "output": "0",
              "balance": "0"
            }
          }
        },
        "reverted": false
      }
    ],
    "accountMetadata": {
      "users:001": {
        "name": "John Doe",
        "email": "john@example.com"
      },
      "payments:001": {
        "type": "payment_processor",
        "provider": "stripe"
      }
    }
  }
}
```

## Publishing to Kafka

An integration with Kafka is available out of the box since 1.3. It pushes ledger events to a Kafka broker of your choice. Enable it with
setting the [configuration variables](https://docs.formance.com/deploy/self-hosted/config/settings) `PUBLISHER_KAFKA_ENABLED`, `PUBLISHER_KAFKA_BROKER` and `PUBLISHER_TOPIC_MAPPING`.

Other [variables](https://docs.formance.com/deploy/self-hosted/config/settings) are available for further authentication and configuration.

Applies to: deployment=cloud.

Access to Kafka publishing is not yet available in Formance Cloud.

The event payload format is the same as for HTTP publishing:

A COMMITTED\_TRANSACTIONS event published when new transactions are committed to a ledger. Contains the complete transaction data including postings, volumes, and associated account metadata.

```json
{
  "date": "2024-01-15T10:30:00Z",
  "app": "ledger",
  "version": "v2",
  "type": "COMMITTED_TRANSACTIONS",
  "payload": {
    "ledger": "quickstart",
    "transactions": [
      {
        "id": 1,
        "postings": [
          {
            "source": "world",
            "destination": "users:001",
            "amount": "100",
            "asset": "USD"
          },
          {
            "source": "users:001",
            "destination": "payments:001",
            "amount": "100",
            "asset": "USD"
          }
        ],
        "metadata": {
          "category": "payment",
          "reference": "tx_001"
        },
        "timestamp": "2024-01-15T10:30:00Z",
        "insertedAt": "2024-01-15T10:30:01Z",
        "updatedAt": "2024-01-15T10:30:01Z",
        "reference": "payment_001",
        "postCommitVolumes": {
          "users:001": {
            "USD": {
              "input": "100",
              "output": "100",
              "balance": "0"
            }
          },
          "payments:001": {
            "USD": {
              "input": "100",
              "output": "0",
              "balance": "100"
            }
          },
          "world": {
            "USD": {
              "input": "0",
              "output": "100",
              "balance": "-100"
            }
          }
        },
        "preCommitVolumes": {
          "users:001": {
            "USD": {
              "input": "0",
              "output": "0",
              "balance": "0"
            }
          },
          "payments:001": {
            "USD": {
              "input": "0",
              "output": "0",
              "balance": "0"
            }
          },
          "world": {
            "USD": {
              "input": "0",
              "output": "0",
              "balance": "0"
            }
          }
        },
        "reverted": false
      }
    ],
    "accountMetadata": {
      "users:001": {
        "name": "John Doe",
        "email": "john@example.com"
      },
      "payments:001": {
        "type": "payment_processor",
        "provider": "stripe"
      }
    }
  }
}
```
