# Channels and Topics

In EW Data Exchange, the DDHub Message Broker is analogous to a computer - it is foundational infrastructure upon which participants gain the ability to establish their own “profiles”, exchange messages, and run their own applications. The DDHub Message Broker routes and translates messages between participants. Messages are structured and organised in distinct `channels` corresponding to specific use cases or business processes, and formatted in topics which define data formats and schemas.

In order to access certain channels and gain permissions to send and/or receive specific message types, participants must acquire roles that reflect their role within the market (or use case), using credentials attached to their self-determined identity. Credentials are granted by a platform governing body and determine the ability to send messages to other participants using channels (what messages are sent and received) and topics (data schemas that define the payload of a message).

## Channels

Channels are defined at the client gateway, and are what messages are sent and received on. Participants define a channel as:

* `Type`: Publish/Subscribe
* `Topics`: Any that the DID has visibility of
* `Restrictions`: Who will receive a message on a publish channel, or who I will receive a message from on a sub channel. Channels can be restricted by DID or role

\
An example of a channel definition object is provided below. In this example, the channel will receive `RealTimePricing` or `DayAheadPricing` from any DID with the role: user.roles.internal.apps.operator.iam.ewc and does not specify that payload encryption is required.

```
// Market Pricing Channel Example
 {
        "fqcn": "pricingtopics.sub",
        "type": "sub",
        "conditions": {
            "topics": [
                {
                    "topicName": "RealTimePricing",
                    "owner": "internal.apps.operator.iam.ewc",
                    "topicId": "62f9b4123bef104db2264f2b",
                    "schemaType": "JSD7"
                },
                {
                    "topicName": "DayAheadPricing",
                    "owner": "internal.apps.operator.iam.ewc",
                    "topicId": "62f9b4644bfe104db22642c0",
                    "schemaType": "JSD7"
                }
            ],
            "dids": [],
            "roles": [
                "user.roles.internal.apps.operator.iam.ewc"
            ],
            "qualifiedDids": [
                "did:ethr:volta:0x135ebb63ab839bef3e292e55dcF4A98Bfe38Ba47A9",
                "did:ethr:volta:0x87795f53b443ece663986f46e6747fb10dbc6745fC"
            ]
        },
        "payloadEncryption": false,
        "createdDate": "2022-08-16T00:03:46.164Z",
        "updatedDate": "2022-09-04T22:33:43.313Z"
    }


```

\
Topics
------

Topics are data schemas that define the payload of a message within a channel. They are grouped under owners that are used as an authorization unit for visibility. Two examples of Topics for publishing and acknowledging a distribution network line constraint are provided below:

```
// Constraint Publication Example
{
    "participantId": "string",
    "submissionTimestamp": "string",
    "networkConstraints": [
        {
            "meterID": "string:",
            "intervals": [
                {
                    "activePowerExportLimit": 0.0,
                    "activePowerImportLimit": 0.0,
                    "diEndtime": "string",
                    "diStarttime": "string"
                }
            ]
        }
    ]
}
```

```
// Constraint Acknowledgement Example
{
    "data": {
        "initiatingMessageId": "string",
        "initiatingTransactionId": "string",
        "systemProcessedDttm": "datetime"
    },
    "acknowledgements": [
        {
            "code": "string",
            "title": "string",
            "detail": "string",
            "source": "string"
        }
    ],
    "errors": [
        {
            "code": "string",
            "title": "string",
            "detail": "string",
            "source": "string"
        }
    ],
    "warnings": [
        {
            "code": "string",
            "title": "string",
            "detail": "string",
            "source": "string"
        }
    ]
}
```

\
\
\\
