diff --git a/docker-compose/local/infra-mq-nats.yml b/docker-compose/local/infra-mq-nats.yml index 00eb668..dcf798d 100644 --- a/docker-compose/local/infra-mq-nats.yml +++ b/docker-compose/local/infra-mq-nats.yml @@ -27,12 +27,18 @@ services: image: nats:alpine3.20 container_name: nats restart: unless-stopped - command: [ "-js" ] # TODO X: 启用 JetStream + command: [ + "-js", # TODO X: 启用 JetStream + "-m", "8222" # 启用 HTTP 监控并指定端口 + ] ports: - '4222:4222' - '6222:6222' - '8222:8222' + volumes: + - nats_data:/data + networks: - nats_net @@ -45,4 +51,6 @@ services: networks: nats_net: - +# 自定义数据卷: +volumes: + nats_data: diff --git a/packages/try-nats/py/src/try_nats/run_kv.py b/packages/try-nats/py/src/try_nats/run_kv.py index 5ec7137..cab1112 100644 --- a/packages/try-nats/py/src/try_nats/run_kv.py +++ b/packages/try-nats/py/src/try_nats/run_kv.py @@ -15,12 +15,17 @@ async def main(): # Create a KV kv = await js.create_key_value(bucket='MY_KV') + for i in range(5): + await kv.put(f'key_{i}', b'value_{i}') + # Set and retrieve a value await kv.put('hello', b'world') entry = await kv.get('hello') - print(f'KeyValue.Entry: key={entry.key}, value={entry.value}') + logger.debug(f'KeyValue.Entry: key={entry.key}, value={entry.value}') # KeyValue.Entry: key=hello, value=world + logger.debug(f"kv: {await kv.status()}") + await nc.close()