Skip to content

Commit f7d1a22

Browse files
committed
Update README
1 parent 8e824a3 commit f7d1a22

1 file changed

Lines changed: 105 additions & 1 deletion

File tree

README.md

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Suhaib Message Queue (SMQ) is an ultra-lightweight, efficient messaging queue sy
88
- **Flexible Deployment Options**: Run as a Docker container, integrate within Go applications, or operate as a standalone executable.
99
- **Reliable Persistence**: Uses SQLite to store messages on disk with a write-ahead log and rollback journal, ensuring data durability across restarts and failures.
1010
- **gRPC Integration**: Utilizes gRPC for efficient, scalable communication between distributed services.
11-
- **Client Package**: Includes a client package to facilitate easy integration and communication.
11+
- **Client Packages**: Includes both a Go client package and a Python client package (pysmq on PyPI) to facilitate easy integration and communication across different languages.
1212

1313
## Why Choose SMQ Over Apache Kafka or RabbitMQ?
1414
SMQ is particularly advantageous in environments where simplicity, minimal overhead, and integration ease are paramount over the comprehensive feature sets of larger systems like Apache Kafka or RabbitMQ. It is especially well-suited for:
@@ -194,3 +194,107 @@ func main() {
194194
log.Printf("Received message at offset %d: %s", offset, string(msg))
195195
}
196196
```
197+
198+
## Python Client Usage
199+
200+
SMQ also provides a Python client package (`pysmq`) available on PyPI, which allows Python applications to interact with SMQ servers.
201+
202+
### Installing the Python Client
203+
204+
Install the Python client using pip:
205+
206+
```bash
207+
pip install pysmq
208+
```
209+
210+
### Basic Usage Examples
211+
212+
#### Publishing Messages
213+
214+
Here's an example of how to publish messages to an SMQ server using the Python client:
215+
216+
```python
217+
import json
218+
import time
219+
from pysmq.client import Client
220+
221+
# Create a client
222+
with Client(host="localhost", port=8097) as client:
223+
# Connect to the server
224+
client.connect()
225+
226+
# Create a topic
227+
topic = "example-topic"
228+
client.create_topic(topic)
229+
230+
# Publish a message
231+
message = {
232+
"id": 1,
233+
"timestamp": time.time(),
234+
"content": "Hello from Python!",
235+
}
236+
message_bytes = json.dumps(message).encode('utf-8')
237+
238+
# Produce the message
239+
offset = client.produce(topic, message_bytes)
240+
print(f"Message published at offset {offset}")
241+
```
242+
243+
#### Consuming Messages
244+
245+
Here's an example of how to consume messages:
246+
247+
```python
248+
import json
249+
from pysmq.client import Client
250+
251+
# Create a client
252+
with Client(host="localhost", port=8097) as client:
253+
# Connect to the server
254+
client.connect()
255+
256+
topic = "example-topic"
257+
258+
# Consume the latest message
259+
message_bytes, offset = client.consume_latest(topic)
260+
261+
# Process the message
262+
message = json.loads(message_bytes.decode('utf-8'))
263+
print(f"Received message at offset {offset}:")
264+
print(f"Content: {message.get('content')}")
265+
266+
# Stream consumption example
267+
print("Starting stream consumption...")
268+
for message_bytes, offset in client.stream_consume(topic, start_offset=0):
269+
message = json.loads(message_bytes.decode('utf-8'))
270+
print(f"Received message at offset {offset}: {message.get('content')}")
271+
# Break condition (example: stop after processing 10 messages)
272+
if offset >= 10:
273+
break
274+
```
275+
276+
#### Secure Connection with mTLS
277+
278+
The Python client also supports secure connections using mTLS:
279+
280+
```python
281+
from pysmq.client import Client
282+
from pysmq.config import ClientTLSConfig
283+
284+
# Create a TLS configuration
285+
tls_config = ClientTLSConfig(
286+
cert_file="/path/to/client.crt",
287+
key_file="/path/to/client.key",
288+
ca_file="/path/to/ca.crt",
289+
)
290+
291+
# Create a secure client
292+
with Client(host="localhost", port=8097, tls_config=tls_config) as client:
293+
# Connect securely
294+
client.connect()
295+
print("Connected securely!")
296+
297+
# Now you can use the client as in the previous examples
298+
```
299+
300+
For more detailed examples, refer to the Python client documentation and example files in the `pysmq/examples` directory.

0 commit comments

Comments
 (0)