@@ -35,6 +35,69 @@ let consul_config = Config {
35
35
.. Default :: default () // Uses default values for other settings
36
36
};
37
37
38
+ let consul = Consul :: new (consul_config );
39
+ ```
40
+ ### Register a Service
41
+ ``` rust
42
+ let node_id = " root-node" ; // node name
43
+ let service_name = " new-service-1" ; // service name
44
+
45
+ let payload = RegisterEntityPayload {
46
+ ID : None ,
47
+ Node : node_id . to_string (),
48
+ Address : " 127.0.0.1" . to_string (), // server address
49
+ Datacenter : None ,
50
+ TaggedAddresses : Default :: default (),
51
+ NodeMeta : Default :: default (),
52
+ Service : Some (RegisterEntityService {
53
+ ID : None ,
54
+ Service : service_name . to_string (),
55
+ Tags : vec! [],
56
+ TaggedAddresses : Default :: default (),
57
+ Meta : Default :: default (),
58
+ Port : Some (42424 ),
59
+ Namespace : None ,
60
+ }),
61
+ Check : None ,
62
+ SkipNodeUpdate : None ,
63
+ };
64
+
65
+ consul . register_entity (& payload ). await . unwrap ();
66
+ ```
67
+ ### Deregister a service
68
+ ``` rust
69
+ let node_id = " root-node" ;
70
+ let service_name = " new-service-1" ;
71
+
72
+ let payload = DeregisterEntityPayload {
73
+ Node : Some (node_id . to_string ()),
74
+ Datacenter : None ,
75
+ CheckID : None ,
76
+ ServiceID : Some (service_name . to_string ()),
77
+ Namespace : None ,
78
+ };
79
+ consul . deregister_entity (& payload ). await . unwrap ();
80
+ ```
81
+ ## Usage
82
+ Check [ /examples] ( /examples ) for more detailed usage
83
+ ### Initialize the client
84
+ #### Environment Configuration (Recommended)
85
+ The client can be configured automatically using environment variables:
86
+ ``` rust
87
+ use rs_consul :: {types :: * , Config , Consul };
88
+
89
+ let consul_config = Config :: from_env ();
90
+ let consul = Consul :: new (consul_config );
91
+ ```
92
+ #### Manual Configuration
93
+ Alternatively, you can configure the client manually:
94
+ ``` rust
95
+ let consul_config = Config {
96
+ address : " http://localhost:8500" . to_string (),
97
+ token : None , // No token required in development mode
98
+ .. Default :: default () // Uses default values for other settings
99
+ };
100
+
38
101
let consul = Consul :: new (consul_config );
39
102
```
40
103
### Register a Service
0 commit comments