ethanlin01x commented on code in PR #3776:
URL: https://github.com/apache/iggy/pull/3776#discussion_r3723575362
##########
examples/python/getting-started/consumer.py:
##########
@@ -91,34 +99,30 @@ def parse_args() -> ArgNamespace:
return ArgNamespace(**vars(args))
-def build_connection_string(args) -> str:
- """Build a connection string with TLS support."""
-
- conn_str =
f"iggy://{args.username}:{args.password}@{args.tcp_server_address}"
-
- if args.tls:
- # Extract domain from server address (host:port -> host)
- host = args.tcp_server_address.split(":")[0]
- query_params = ["tls=true", f"tls_domain={host}"]
+def build_config(args: ArgNamespace) -> TcpConfig:
+ """Build a TCP client configuration with auto-login and reconnection."""
- # Add CA file if provided
- if args.tls_ca_file:
- query_params.append(f"tls_ca_file={args.tls_ca_file}")
- conn_str += "?" + "&".join(query_params)
-
- return conn_str
+ return TcpConfig(
+ server_address=args.tcp_server_address,
+ auto_login=AutoLogin.username_password(args.username, args.password),
+ reconnection=TcpReconnectionConfig(
+ enabled=True,
+ interval=timedelta(seconds=1),
+ ),
+ tls_enabled=args.tls,
+ tls_ca_file=args.tls_ca_file or None,
+ )
async def main():
args: ArgNamespace = parse_args()
+ config = build_config(args)
Review Comment:
Fixed in 72025b394 — both examples catch the ValueError and print the
message instead of a traceback.
##########
foreign/python/README.md:
##########
@@ -58,6 +58,42 @@ maturin develop
pytest tests/ -v # Run tests (requires iggy-server running)
```
+## Client Configuration
+
+`IggyClient` takes either a server address or a `TcpConfig`:
+
+```python
+import asyncio
+from datetime import timedelta
+
+from apache_iggy import AutoLogin, IggyClient, TcpConfig, TcpReconnectionConfig
+
+
+async def main():
+ client = IggyClient(
+ TcpConfig(
+ server_address="127.0.0.1:8090",
+ auto_login=AutoLogin.username_password("iggy", "iggy"),
+ reconnection=TcpReconnectionConfig(
+ enabled=True,
+ max_retries=10,
+ interval=timedelta(seconds=2),
+ reestablish_after=timedelta(seconds=30),
+ ),
+ heartbeat_interval=timedelta(seconds=5),
+ # tls_enabled=True,
+ # tls_domain="localhost",
+ # tls_ca_file="core/certs/iggy_ca_cert.pem",
Review Comment:
Fixed in 71e3936da.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]