|
| 1 | +## *🕸️ MqttDistribNet* - A structured distribution network for amqp messaging |
| 2 | + |
| 3 | +The MqttDistribNet module consist of two concepts, to ease the usage of amqp brokers: |
| 4 | +- **Dynamic Infrastructure Management**<br> |
| 5 | + To simplify the configuration of topics and queues and binding them in a logical path, |
| 6 | + we introduced an <code>IDistributionNetworkManager</code> and <code>IRemoteDistributionNetworkManager</code>. |
| 7 | + While the <code>IDistributionNetworkManager</code> is the infrastructure management server, the <code>IRemoteDistributionNetworkManager</code> |
| 8 | + is used by the client to get information about the remote managed infrastructure. |
| 9 | +- **Simple Message Distribution**<br> |
| 10 | + Based on Request/Response and Publish/Subscribe Patterns we created <code>Handler</code>, <code>Consumer</code> and <code>Clients</code> to easily |
| 11 | + configure the wanted behaviour behind queues and reach them by their configured message type. |
| 12 | + |
| 13 | +### 1. Usage: |
| 14 | +```go |
| 15 | +import ( |
| 16 | + mqttdistribnet "github.com/tjarkpr/mqttdistribnet/pkg" |
| 17 | + amqp "github.com/rabbitmq/amqp091-go" |
| 18 | +) |
| 19 | +``` |
| 20 | +#### 1.1. DistributionNetworkManager |
| 21 | +```go |
| 22 | +connection, err := amqp.Dial(url) |
| 23 | +manager, err := mqttdistribnet.MakeIDistributionNetworkManager(connection, "<prefix>") |
| 24 | +logs, err := manager.Start(&ctx) |
| 25 | +``` |
| 26 | +#### 1.2. Distribution & Consumption |
| 27 | +```go |
| 28 | +connection, err := amqp.Dial(url) |
| 29 | +remote, err := mqttdistribnet.MakeIRemoteDistributionNetworkManager(connection, "<prefix>") |
| 30 | +``` |
| 31 | +```go |
| 32 | +remote.Register(reflect.TypeFor[mqttdistribnet.Envelope[TestRequest]](), "L1.L2.L3.L4.*") |
| 33 | +``` |
| 34 | +```go |
| 35 | +err = mqttdistribnet.MakeRequestHandler[mqttdistribnet.Envelope[TestRequest], mqttdistribnet.Envelope[TestResponse]]( |
| 36 | + remote, |
| 37 | + func(request mqttdistribnet.Envelope[TestRequest]) (mqttdistribnet.Envelope[TestResponse], error) { |
| 38 | + t.Log("Request: " + request.ToString()) |
| 39 | + return mqttdistribnet.Envelope[TestResponse]{ |
| 40 | + MessageId: uuid.New(), |
| 41 | + Timestamp: time.Now(), |
| 42 | + Payload: TestResponse{TestResProperty: "Test"}, |
| 43 | + }, nil |
| 44 | +}, &ctx) |
| 45 | +``` |
| 46 | +```go |
| 47 | +request := &mqttdistribnet.Envelope[TestRequest]{ |
| 48 | + MessageId: uuid.New(), |
| 49 | + Timestamp: time.Now(), |
| 50 | + Payload: TestRequest{TestReqProperty: "Test"}, |
| 51 | +} |
| 52 | +clients, err := mqttdistribnet.MakeRequestClient[mqttdistribnet.Envelope[TestRequest], mqttdistribnet.Envelope[TestResponse]](remote) |
| 53 | +response, err := slices.Collect(maps.Values(clients))[0].Send(request) |
| 54 | +``` |
0 commit comments