0

Is there any way I can fetch Hystrix streams (which produces metrices), since it is a server side event stream, thus it is not possible to fetch it using normal http client.

I was trying to using Jersey based SSE, however it is not able to do so.

Whenever, hystrix makes a call it produces some metrics data which can be accessed through a servlet (sample url for which is like: ::/hystrix.stream).

I want to capture response of this stream on a particular time.

Any way to do this?

Thank You.

Lovey
  • 880
  • 3
  • 15
  • 31

1 Answers1

0

You can catch any SSE events with jersey client. Here is a example that read from a SSE events as source and broadcast it to any clients that call consumeEvent resource method:

@Path("ssetest")
@Singleton
public class SSETest {
private static final SseBroadcaster sseBroadcaster = new SseBroadcaster();

private static OutboundEvent convert(InboundEvent in){
    OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
    OutboundEvent out = eventBuilder.comment(in.getComment())
            .data(in.readData())
            .id(in.getId())
            .name(in.getName())
            .build();
    return out;
}

static {
    Client client = ClientBuilder.newBuilder().register(SseFeature.class).build();
    WebTarget target = client.target("http://path/to/the/any/sse/event/producer/such/as/hystrix");
    EventSource eventSource = EventSource.target(target).build();
    EventListener listener = new EventListener() {
        @Override
        public void onEvent(InboundEvent inboundEvent) {
            sseBroadcaster.broadcast(convert(inboundEvent));
        }
    };
    eventSource.register(listener, "event");
    eventSource.open();
}

@GET
@Path("consumeEvent")
@Produces(SseFeature.SERVER_SENT_EVENTS)
public EventOutput consumeEvent(){
    EventOutput output = new EventOutput();
    sseBroadcaster.add(output);
    return output;
}

}

The static part make a call to SSE event producer and it gets events with EventListener. Please note that EventSource only registered this listener to the SSE events with "event" name. You must register it with the name of hystrix event name.
Each time a client call consumeEvent resource method, it will receive the hystrix events.

Alireza
  • 31
  • 1
  • 6