Skip to content

Commit 7705b73

Browse files
authored
chore: Add example for using multi region setup in a single application (#849)
1 parent 3de6c4f commit 7705b73

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ Twilio.setEdge("sydney");
266266

267267
This will result in the `hostname` transforming from `api.twilio.com` to `api.sydney.au1.twilio.com`.
268268

269+
To use multiple region within same application, refer [MultiRegionClient.md](https://github.com/twilio/twilio-java/blob/main/examples/MultiRegionClient.md)
270+
269271
### Enable Debug Logging
270272

271273
This library uses SLF4J for logging. Consult the [SFL4J documentation](http://slf4j.org/docs.html) for information about logging configuration.

examples/MultiRegionClient.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
```java
2+
package com.twilio.example;
3+
4+
import com.twilio.http.TwilioRestClient;
5+
import com.twilio.rest.api.v2010.account.Message;
6+
import com.twilio.type.PhoneNumber;
7+
8+
public class MultiRegionExample {
9+
public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
10+
public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
11+
12+
public static void main(String[] args) {
13+
14+
TwilioRestClient client = new TwilioRestClient.Builder(ACCOUNT_SID, AUTH_TOKEN).region("us1").build();
15+
16+
Message message = Message
17+
.creator(
18+
new PhoneNumber("+1XXXXXXXXXX"),
19+
new PhoneNumber("+1XXXXXXXXXX"),
20+
"This is the ship that made the Kessel Run in fourteen parsecs?"
21+
)
22+
.create(client);
23+
24+
System.out.println(message.getSid());
25+
26+
TwilioRestClient client2 = new TwilioRestClient.Builder(ACCOUNT_SID, AUTH_TOKEN).region("au1").build();
27+
28+
Message message2 = Message
29+
.creator(
30+
new PhoneNumber("+1XXXXXXXXXX"),
31+
new PhoneNumber("+1XXXXXXXXXX"),
32+
"This is the ship that made the Kessel Run in fourteen parsecs?"
33+
)
34+
.create(client2);
35+
36+
System.out.println(message2.getSid());
37+
}
38+
}
39+
40+
41+
```

0 commit comments

Comments
 (0)