Skip to content

Commit a43e231

Browse files
authored
Update README.md
1 parent 4707f45 commit a43e231

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

hystrix-contrib/hystrix-javanica/README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,32 @@ Based on [this](https://github.com/Netflix/Hystrix/wiki/How-To-Use#ErrorPropagat
326326
}
327327
```
328328

329-
If `userResource.getUserById(id);` throws an exception which type is _BadRequestException_ then this exception will be thrown without triggering fallback logic.
329+
If `userResource.getUserById(id);` throws an exception that type is _BadRequestException_ then this exception will be wrapped in ``HystrixBadRequestException`` and re-thrown without triggering fallback logic. You don't need to do it manually, javanica will do it for you under the hood. It is worth noting that a caller will get root cause exception, i.e. user ``BadRequestException``. A caller always gets root cause exception, never ``HystrixBadRequestException`` or ``HystrixRuntimeException`` except the case when executed code explicitly throws those exceptions.
330+
331+
*Note*: If command has a fallback then only first exception that trigers fallback logic will be propagated to caller. Example:
332+
333+
```java
334+
class Service {
335+
@HystrixCommand(fallbackMethod = "fallback")
336+
Object command(Object o) throws CommandException {
337+
throw new CommandException();
338+
}
339+
340+
@HystrixCommand
341+
Object fallback(Object o) throws FallbackException {
342+
throw new FallbackException();
343+
}
344+
}
345+
346+
// in client code
347+
{
348+
try {
349+
service.command(null);
350+
} catch (Exception e) {
351+
assert CommandException.class.equals(e.getClass())
352+
}
353+
}
354+
```
330355

331356
## Request Cache
332357

@@ -531,6 +556,24 @@ ThreadPoolProperties can be set using @HystrixCommand's 'threadPoolProperties' l
531556
}
532557
```
533558

559+
### DefaultProperties
560+
``@DefaultProperties`` is class (type) level annotation that allows to default commands properties such as ``groupKey``, ``threadPoolKey``, ``commandProperties``, ``threadPoolProperties`` and ``ignoreExceptions``. Properties specified using this annotation will be used by default for each hystrix command defined within annotated class unless a command specifies those properties explicitly using corresponding ``@HystrixCommand`` parameters.
561+
Example:
562+
563+
```java
564+
@DefaultProperties(groupKey = "DefaultGroupKey")
565+
class Service {
566+
@HystrixCommand // hystrix command group key is 'DefaultGroupKey'
567+
public Object commandInheritsDefaultProperties() {
568+
return null;
569+
}
570+
@HystrixCommand(groupKey = "SpecificGroupKey") // command overrides default group key
571+
public Object commandOverridesGroupKey() {
572+
return null;
573+
}
574+
}
575+
```
576+
534577
## Hystrix collapser
535578

536579
Suppose you have some command which calls should be collapsed in one backend call. For this goal you can use ```@HystrixCollapser``` annotation.

0 commit comments

Comments
 (0)