Skip to content

Commit b1a7af2

Browse files
authored
added option resolver Get fixes, readme update (#108)
1 parent 2862447 commit b1a7af2

File tree

2 files changed

+49
-34
lines changed

2 files changed

+49
-34
lines changed

messaging/README.md

+48-33
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,88 @@
33
This is a flexible and extensible messaging client designed to provide a unified interface for producing and consuming messages across various messaging platforms. It allows developers to seamlessly integrate messaging functionality into their applications without being tied to a specific messaging service.
44

55
---
6+
67
- [Features](#features)
78
- [Installation](#installation)
89
- [Usage](#usage)
910
- [Extending the library](#extending-the-library)
11+
1012
---
1113

1214
## Features
13-
* General producer interface for sending messages to different messaging platforms.
14-
* General consumer interface for receiving and processing messages from different messaging platforms.
15-
* Supports QualityOfService features such as
16-
* CircuitBreaker
17-
* Retry
18-
* Easy-to-use message abstraction for consistent handling of messages across platforms.
19-
* Can be extended to multiple messaging platforms with easily pluggable interfaces, including:
20-
* AMQP (Advanced Message Queuing Protocol)
21-
* Apache Kafka
22-
* AWS SNS (Simple Notification Service)
23-
* AWS SQS (Simple Queue Service)
24-
* GCM (Google Cloud Messaging)
25-
* GCP Pub/Sub (Google Cloud Pub/Sub)
15+
16+
- General producer interface for sending messages to different messaging platforms.
17+
- General consumer interface for receiving and processing messages from different messaging platforms.
18+
- Supports QualityOfService features such as
19+
- CircuitBreaker
20+
- Retry
21+
- Easy-to-use message abstraction for consistent handling of messages across platforms.
22+
- Can be extended to multiple messaging platforms with easily pluggable interfaces, including:
23+
- AMQP (Advanced Message Queuing Protocol)
24+
- Apache Kafka
25+
- AWS SNS (Simple Notification Service)
26+
- AWS SQS (Simple Queue Service)
27+
- GCM (Google Cloud Messaging)
28+
- GCP Pub/Sub (Google Cloud Pub/Sub)
2629

2730
## Installation
31+
2832
To install the messaging client, use the following command:
33+
2934
```bash
3035
go get oss.nandlabs.io/golly/clients/messaging
3136
```
3237

3338
## Usage
39+
3440
1. Import the library into your Go project:
41+
3542
```go
3643
import "oss.nandlabs.io/golly/clients/messaging"
3744
```
45+
3846
2. Initialize the messaging provider for a specific platform. For example, to use the AMQP extension:
47+
3948
```go
4049
type AMQPProvider struct {} // implements the Provider interface defined under the library
4150
amqpProvider := &AMQPProvider{}
4251
4352
manager := messaging.Get()
4453
manager.Register(amqpProvider)
4554
```
55+
4656
3. Send a message
47-
```go
48-
message := &messaging.Message{
49-
Body: []byte("Hello, World!"),
50-
/// Add any additional properties or metadata
51-
}
52-
destination := url.Parse("amqp://guest:password@localhost:5672/myvhost")
53-
err := manager.Send(destination, message)
54-
if err != nil {
55-
// Handle error
56-
}
57-
```
57+
58+
```go
59+
message := &messaging.Message{
60+
Body: []byte("Hello, World!"),
61+
/// Add any additional properties or metadata
62+
}
63+
destination := url.Parse("amqp://guest:password@localhost:5672/myvhost")
64+
err := manager.Send(destination, message)
65+
if err != nil {
66+
// Handle error
67+
}
68+
```
69+
5870
4. Receive a message
59-
```go
60-
// Define the onReceive function
61-
onReceive := func(msg Message) error {
62-
// Process the message
63-
// ...
71+
72+
```go
73+
// Define the onReceive function
74+
onReceive := func(msg Message) error {
75+
// Process the message
76+
// ...
6477
6578
return nil
66-
}
67-
// Start receiving messages from the channel
68-
manager.Receive(receiverUrl, onReceive)
69-
```
79+
}
80+
// Start receiving messages from the channel
81+
manager.Receive(receiverUrl, onReceive)
82+
```
83+
7084
5. Repeat steps 2-4 for other messaging platforms by initializing the respective clients.
7185

7286
## Extending the library
87+
7388
To add support for additional messaging platforms, you can create new extensions by implementing the producer, consumer, and message interfaces defined in the library. These interfaces provide a consistent way to interact with different messaging systems.
7489

7590
You can refer to the existing extensions, such as amqp, kafka, etc., as examples for creating your own extensions. Ensure that your extension adheres to the interface definitions and follows the library's conventions for consistency.

messaging/options.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ func ResolveOptValue[T any](key string, optionsResolver *OptionsResolver) (value
106106
}
107107

108108
func (or *OptionsResolver) Get(key string) (value interface{}, has bool) {
109-
value, has = or.opts[RetryOpts]
109+
value, has = or.opts[key]
110110
return
111111
}

0 commit comments

Comments
 (0)