Skip to content

Commit 7f29c24

Browse files
committed
iluwatar#590 explanation for Ambassador
1 parent 51e8900 commit 7f29c24

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

ambassador/README.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,37 @@ tags:
1010
---
1111

1212
## Intent
13+
1314
Provide a helper service instance on a client and offload common functionality away from a shared resource.
1415

1516
## Explanation
17+
1618
Real world example
1719

18-
> A remote service has many clients accessing a function it provides. The service is a legacy application and is impossible to update. Large numbers of requests from users are causing connectivity issues. New rules for request frequency should be implemented along with latency checks and client-side logging.
20+
> A remote service has many clients accessing a function it provides. The service is a legacy application and is
21+
> impossible to update. Large numbers of requests from users are causing connectivity issues. New rules for request
22+
> frequency should be implemented along with latency checks and client-side logging.
1923
2024
In plain words
2125

22-
> Using the ambassador pattern, we can implement less-frequent polling from clients along with latency checks and logging.
26+
> With the Ambassador pattern, we can implement less-frequent polling from clients along with latency checks and
27+
> logging.
2328
2429
Microsoft documentation states
2530

26-
> An ambassador service can be thought of as an out-of-process proxy that is co-located with the client. This pattern can be useful for offloading common client connectivity tasks such as monitoring, logging, routing, security (such as TLS), and resiliency patterns in a language agnostic way. It is often used with legacy applications, or other applications that are difficult to modify, in order to extend their networking capabilities. It can also enable a specialized team to implement those features.
31+
> An ambassador service can be thought of as an out-of-process proxy which is co-located with the client. This pattern
32+
> can be useful for offloading common client connectivity tasks such as monitoring, logging, routing,
33+
> security (such as TLS), and resiliency patterns in a language agnostic way. It is often used with legacy applications,
34+
> or other applications that are difficult to modify, in order to extend their networking capabilities. It can also
35+
> enable a specialized team to implement those features.
2736
2837
**Programmatic Example**
2938

30-
With the above example in mind we will imitate the functionality in a simple manner. We have an interface implemented by the remote service as well as the ambassador service:
39+
With the above introduction in mind we will imitate the functionality in this example. We have an interface implemented
40+
by the remote service as well as the ambassador service:
3141

3242
```java
3343
interface RemoteServiceInterface {
34-
3544
long doRemoteFunction(int value) throws Exception;
3645
}
3746
```
@@ -136,7 +145,7 @@ public class Client {
136145
}
137146
```
138147

139-
And here are two clients using the service.
148+
Here are two clients using the service.
140149

141150
```java
142151
public class App {
@@ -149,13 +158,29 @@ public class App {
149158
}
150159
```
151160

161+
Here's the output for running the example:
162+
163+
```java
164+
Time taken (ms): 111
165+
Service result: 120
166+
Time taken (ms): 931
167+
Failed to reach remote: (1)
168+
Time taken (ms): 665
169+
Failed to reach remote: (2)
170+
Time taken (ms): 538
171+
Failed to reach remote: (3)
172+
Service result: -1
173+
```
174+
152175
## Class diagram
176+
153177
![alt text](./etc/ambassador.urm.png "Ambassador class diagram")
154178

155179
## Applicability
156-
Ambassador is applicable when working with a legacy remote service that cannot
157-
be modified or would be extremely difficult to modify. Connectivity features can
158-
be implemented on the client avoiding the need for changes on the remote service.
180+
181+
Ambassador is applicable when working with a legacy remote service which cannot be modified or would be extremely
182+
difficult to modify. Connectivity features can be implemented on the client avoiding the need for changes on the remote
183+
service.
159184

160185
* Ambassador provides a local interface for a remote service.
161186
* Ambassador provides logging, circuit breaking, retries and security on the client.
@@ -168,10 +193,14 @@ be implemented on the client avoiding the need for changes on the remote service
168193
* Offload remote service tasks
169194
* Facilitate network connection
170195

171-
## Real world examples
196+
## Known uses
172197

173198
* [Kubernetes-native API gateway for microservices](https://github.com/datawire/ambassador)
174199

200+
## Related patterns
201+
202+
* [Proxy](https://java-design-patterns.com/patterns/proxy/)
203+
175204
## Credits
176205

177206
* [Ambassador pattern](https://docs.microsoft.com/en-us/azure/architecture/patterns/ambassador)

ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
interface RemoteServiceInterface {
3030
int FAILURE = -1;
3131

32-
long doRemoteFunction(int value) throws Exception;
32+
long doRemoteFunction(int value);
3333
}

proxy/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,16 @@ are several common situations in which the Proxy pattern is applicable
132132

133133
* [Controlling Access With Proxy Pattern](http://java-design-patterns.com/blog/controlling-access-with-proxy-pattern/)
134134

135-
## Real world examples
135+
## Known uses
136136

137137
* [java.lang.reflect.Proxy](http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Proxy.html)
138138
* [Apache Commons Proxy](https://commons.apache.org/proper/commons-proxy/)
139139
* Mocking frameworks Mockito, Powermock, EasyMock
140140

141+
## Related patterns
142+
143+
* [Ambassador](https://java-design-patterns.com/patterns/ambassador/)
144+
141145
## Credits
142146

143147
* [Design Patterns: Elements of Reusable Object-Oriented Software](https://www.amazon.com/gp/product/0201633612/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0201633612&linkCode=as2&tag=javadesignpat-20&linkId=675d49790ce11db99d90bde47f1aeb59)

0 commit comments

Comments
 (0)