Skip to content

Commit

Permalink
Made SSE timeout configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Asgeir Nilsen committed Nov 6, 2017
1 parent d99978e commit 1be4359
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ repositories {

dependencies {
compile('no.fint:fint-audit-mongo-plugin:1.1.1')
compile('no.fint:fint-events:1.0.0')
compile('no.fint:fint-events:1.0.1')
compile('no.fint:fint-event-model:2.0.0')
compile('no.fint:fint-springfox-extension:0.0.1')

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/no/fint/provider/events/ProviderProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public class ProviderProps {
@Value("${fint.provider.event-state.list-name:current-corrids}")
private String key;

@Value("${fint.provider.sse-timeout-minutes:60}")
private int sseTimeoutMinutes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public void cleanUpEventStates() {
eventStates.forEach(eventState -> {
if (eventState.expired()) {
Event event = eventState.getEvent();
log.info("EventState with corrId {} is expired, removing from list", eventState.getCorrId());
log.info("EventState with corrId {} for orgId {} is expired, removing from list", eventState.getCorrId(), eventState.getEvent().getOrgId());
log.debug("Event details: {}", eventState);
eventStateService.remove(event);

event.setMessage("Event expired");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ResponseService {
private FintEvents fintEvents;

public void handleAdapterResponse(Event event) {
log.info("Event received: {}, action: {}", event.getCorrId(), event.getAction());
log.info("Event received: {}, action: {}, orgId: {}", event.getCorrId(), event.getAction(), event.getOrgId());
if (event.isHealthCheck()) {
RBlockingQueue<Event> healthCheckQueue = fintEvents.getTempQueue(event.getCorrId());
fintAuditService.audit(event, Status.TEMP_UPSTREAM_QUEUE);
Expand All @@ -42,7 +42,7 @@ public void handleAdapterResponse(Event event) {
fintAuditService.audit(event);
eventStateService.remove(event);
} else {
log.error("EventState with corrId {} was not found. Either the Event has expired or the provider does not recognize the corrId. action:{} status:{}", event.getCorrId(), event.getAction(), event.getStatus());
log.error("EventState with corrId {} was not found. Either the Event has expired or the provider does not recognize the corrId. {}", event.getCorrId(), event);
throw new UnknownEventException();
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/no/fint/provider/events/sse/SseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
@Slf4j
@Service
public class SseService {
private static final long DEFAULT_TIMEOUT = TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS);

@Autowired
private ProviderProps providerProps;

Expand All @@ -40,7 +38,7 @@ public SseEmitter subscribe(String id, String orgId) {
return registeredEmitter.get();
} else {
log.info("id: {}, {} connected", id, orgId);
FintSseEmitter emitter = new FintSseEmitter(id, DEFAULT_TIMEOUT);
FintSseEmitter emitter = new FintSseEmitter(id, TimeUnit.MINUTES.toMillis(providerProps.getSseTimeoutMinutes()));
emitter.onCompletion(() -> {
log.info("onCompletion called for {}, id: {}", orgId, emitter.getId());
removeEmitter(orgId, emitter);
Expand Down Expand Up @@ -84,8 +82,9 @@ public void send(Event event) {
SseEmitter.SseEventBuilder builder = SseEmitter.event().id(event.getCorrId()).name(event.getAction()).data(event).reconnectTime(5000L);
emitter.send(builder);
} catch (Exception e) {
log.warn("Exception when trying to send message to SseEmitter", e);
log.warn("Exception when trying to send message to SseEmitter", e.getMessage());
log.warn("Removing subscriber {}", event.getOrgId());
log.debug("Details: {}", event, e);
toBeRemoved.add(emitter);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void updateEventState(Event event) {
eventStateService.remove(event);
}
} else {
log.error("EventState with corrId {} was not found. Either the Event has expired or the provider does not recognize the corrId. action:{} status:{}", event.getCorrId(), event.getAction(), event.getStatus());
log.error("EventState with corrId {} was not found. Either the Event has expired or the provider does not recognize the corrId. {}", event.getCorrId(), event);
throw new UnknownEventException();
}
}
Expand Down

0 comments on commit 1be4359

Please sign in to comment.