Search in sources :

Example 1 with SymphonyRoomSharedLog

use of org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog in project spring-bot by finos.

the class SymphonyLeaderEventFilterIT method testMultipleStreamingConsumers.

@Test
public void testMultipleStreamingConsumers() throws InterruptedException {
    List<SimpleEventConsumer> consumers = IntStream.range(0, 4).mapToObj(i -> new Participant("p" + i)).map(p -> new SimpleEventConsumer(p)).collect(Collectors.toList());
    List<SymphonyStreamHandler> wrapped = consumers.stream().map(c -> {
        lmh = new SymphonyRoomSharedLog(clusterName, streamId, messagesApi, "UNIT", 6000);
        SymphonyStreamHandler out = new SymphonyStreamHandler(singleApi, c, ec, false);
        out.setFilter(new SymphonyLeaderEventFilter(c.p, lmh));
        out.start();
        return out;
    }).collect(Collectors.toList());
    // send some messsages through
    for (int j = 0; j < 8; j++) {
        createLeaderEvent(j % 4);
        for (int k = 0; k < 3; k++) {
            createMessageEvent(k);
        }
    }
    boolean done = false;
    while (!done) {
        Thread.sleep(2000);
        done = consumers.stream().map(c -> c.collection.size() == 6).reduce(true, (a, b) -> a && b);
    }
    wrapped.stream().forEach(c -> c.stop());
}
Also used : IntStream(java.util.stream.IntStream) SymphonyRoomSharedLog(org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog) LogMessageType(org.finos.symphony.toolkit.stream.log.LogMessageType) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) LogMessage(org.finos.symphony.toolkit.stream.log.LogMessage) TestApplication(org.finos.symphony.toolkit.stream.fixture.TestApplication) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Participant(org.finos.symphony.toolkit.stream.Participant) ApiInstance(org.finos.symphony.toolkit.spring.api.factories.ApiInstance) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) SymphonyStreamHandler(org.finos.symphony.toolkit.stream.handler.SymphonyStreamHandler) Test(org.junit.jupiter.api.Test) MessagesApi(com.symphony.api.agent.MessagesApi) List(java.util.List) V4Event(com.symphony.api.model.V4Event) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ExceptionConsumer(org.finos.symphony.toolkit.stream.handler.ExceptionConsumer) StreamEventConsumer(org.finos.symphony.toolkit.stream.StreamEventConsumer) SymphonyLeaderEventFilter(org.finos.symphony.toolkit.stream.handler.SymphonyLeaderEventFilter) SymphonyStreamHandler(org.finos.symphony.toolkit.stream.handler.SymphonyStreamHandler) SymphonyLeaderEventFilter(org.finos.symphony.toolkit.stream.handler.SymphonyLeaderEventFilter) Participant(org.finos.symphony.toolkit.stream.Participant) SymphonyRoomSharedLog(org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with SymphonyRoomSharedLog

use of org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog in project spring-bot by finos.

the class SharedStreamHandlerConfig method symphonySharedLog.

@Bean
@ConditionalOnMissingBean
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
protected synchronized SymphonyRoomSharedLog symphonySharedLog(ApiInstance api) {
    if (!StringUtils.hasText(streamProperties.getCoordinationStreamId())) {
        throw new IllegalArgumentException("Shared Log needs a stream ID to write to.  Please set symphony.stream.coordination-stream-id");
    }
    if (createdLogs.containsKey(api)) {
        return createdLogs.get(api);
    }
    String clusterName = api.getIdentity().getEmail();
    SymphonyRoomSharedLog out = new SymphonyRoomSharedLog(clusterName, streamProperties.getCoordinationStreamId(), api.getAgentApi(MessagesApi.class), streamProperties.getEnvironmentIdentifier(), streamProperties.getParticipantWriteIntervalMillis());
    createdLogs.put(api, out);
    LOG.info("Building Shared Log for " + clusterName);
    return out;
}
Also used : MessagesApi(com.symphony.api.agent.MessagesApi) SymphonyRoomSharedLog(org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog) Scope(org.springframework.context.annotation.Scope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MessagesApi (com.symphony.api.agent.MessagesApi)2 SymphonyRoomSharedLog (org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog)2 V4Event (com.symphony.api.model.V4Event)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 ApiInstance (org.finos.symphony.toolkit.spring.api.factories.ApiInstance)1 Participant (org.finos.symphony.toolkit.stream.Participant)1 StreamEventConsumer (org.finos.symphony.toolkit.stream.StreamEventConsumer)1 TestApplication (org.finos.symphony.toolkit.stream.fixture.TestApplication)1 ExceptionConsumer (org.finos.symphony.toolkit.stream.handler.ExceptionConsumer)1 SymphonyLeaderEventFilter (org.finos.symphony.toolkit.stream.handler.SymphonyLeaderEventFilter)1 SymphonyStreamHandler (org.finos.symphony.toolkit.stream.handler.SymphonyStreamHandler)1 LogMessage (org.finos.symphony.toolkit.stream.log.LogMessage)1 LogMessageType (org.finos.symphony.toolkit.stream.log.LogMessageType)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1