github.com/anycable/anycable-go@v1.5.1/etc/nats/README.md (about)

     1  # Testing NATS
     2  
     3  Notes on testing embedded NATS features.
     4  
     5  ## Gateways
     6  
     7  - Run 4 AnyCable RPC servers:
     8  
     9  ```sh
    10  ANYCABLE_BROADCAST_ADAPTER=nats ANYCABLE_NATS_SERVERS=nats://localhost:4242 \
    11  ANYCABLE_RPC_HOST=127.0.0.1:50052 anyt --only-rpc
    12  
    13  ANYCABLE_BROADCAST_ADAPTER=nats ANYCABLE_NATS_SERVERS=nats://localhost:4243 \
    14  ANYCABLE_RPC_HOST=127.0.0.1:50053 anyt --only-rpc
    15  
    16  ANYCABLE_BROADCAST_ADAPTER=nats ANYCABLE_NATS_SERVERS=nats://localhost:4244 \
    17  ANYCABLE_RPC_HOST=127.0.0.1:50054 anyt --only-rpc
    18  
    19  ANYCABLE_BROADCAST_ADAPTER=nats ANYCABLE_NATS_SERVERS=nats://localhost:4245 \
    20  ANYCABLE_RPC_HOST=127.0.0.1:50055 anyt --only-rpc
    21  ```
    22  
    23  - Run 2 clusters with different names and connected to each other via gateways:
    24  
    25  ```sh
    26  # Cluster 1, server 1
    27  ANYCABLE_BROADCAST_ADAPTER=nats ANYCABLE_EMBED_NATS=true \
    28  ANYCABLE_RPC_HOST=127.0.0.1:50052 \
    29  ANYCABLE_ENATS_ADDR=nats://localhost:4242 \
    30  ANYCABLE_ENATS_CLUSTER=nats://localhost:4342 \
    31  ANYCABLE_ENATS_GATEWAY=nats://localhost:4442 \
    32  PORT=8082 make run
    33  
    34  # Cluster 1, server 2
    35  ANYCABLE_BROADCAST_ADAPTER=nats ANYCABLE_EMBED_NATS=true \
    36  ANYCABLE_RPC_HOST=127.0.0.1:50053 \
    37  ANYCABLE_ENATS_ADDR=nats://localhost:4243 \
    38  ANYCABLE_ENATS_CLUSTER=nats://localhost:4343 \
    39  ANYCABLE_ENATS_CLUSTER_ROUTES=nats://localhost:4342 \
    40  ANYCABLE_ENATS_GATEWAY=nats://localhost:4443 \
    41  PORT=8083 make run
    42  
    43  # Cluster 2, server 1
    44  ANYCABLE_BROADCAST_ADAPTER=nats ANYCABLE_EMBED_NATS=true \
    45  ANYCABLE_RPC_HOST=127.0.0.1:50054 \
    46  ANYCABLE_ENATS_CLUSTER_NAME=anycable-cluster-2 \
    47  ANYCABLE_ENATS_ADDR=nats://localhost:4244 \
    48  ANYCABLE_ENATS_CLUSTER=nats://localhost:4344 \
    49  ANYCABLE_ENATS_GATEWAY=nats://localhost:4444 \
    50  ANYCABLE_ENATS_GATEWAYS=anycable-cluster:nats://localhost:4442 \
    51  PORT=8084 make run
    52  
    53  # Cluster 2, server 2
    54  ANYCABLE_BROADCAST_ADAPTER=nats ANYCABLE_EMBED_NATS=true \
    55  ANYCABLE_RPC_HOST=127.0.0.1:50055 \
    56  ANYCABLE_ENATS_CLUSTER_NAME=anycable-cluster-2 \
    57  ANYCABLE_ENATS_ADDR=nats://localhost:4245 \
    58  ANYCABLE_ENATS_CLUSTER=nats://localhost:4345 \
    59  ANYCABLE_ENATS_CLUSTER_ROUTES=nats://localhost:4344 \
    60  ANYCABLE_ENATS_GATEWAY=nats://localhost:4445 \
    61  ANYCABLE_ENATS_GATEWAYS=anycable-cluster:nats://localhost:4442 \
    62  PORT=8085 make run
    63  ```
    64  
    65  - Use `acli` to connect to 4 clients and try to perform the "broadcast" action—all server should receive it:
    66  
    67  ```sh
    68  # client 1
    69  acli -u localhost:8082/cable -c BenchmarkChannel
    70  
    71  # client 2
    72  acli -u localhost:8083/cable -c BenchmarkChannel
    73  
    74  # client 3
    75  acli -u localhost:8084/cable -c BenchmarkChannel
    76  
    77  # client 4
    78  $ acli -u localhost:8085/cable -c BenchmarkChannel
    79  
    80  \p+ broadcast
    81  Enter key (or press ENTER to finish): test
    82  Enter value: gossip
    83  Enter key (or press ENTER to finish):
    84  
    85  {"test":"gossip","action":"broadcastResult"}
    86  {"action":"broadcast","test":"gossip"}
    87  ```