Search in sources :

Example 1 with DatabusV2RegistrationImpl

use of com.linkedin.databus.client.registration.DatabusV2RegistrationImpl in project databus by linkedin.

the class DatabusHttpClientImpl method register.

@Override
public DatabusRegistration register(DatabusCombinedConsumer consumer, String... sources) throws DatabusClientException {
    if ((null == consumer))
        throw new DatabusClientException("No consumer callback has been specified.");
    if ((null == sources) || (sources.length == 0))
        throw new DatabusClientException("Please specify Databus sources to be consumed: register(consumer, source1, source2, ...");
    RegistrationId regId = RegistrationIdGenerator.generateNewId(consumer.getClass().getSimpleName(), DatabusSubscription.createSubscriptionList(Arrays.asList(sources)));
    DatabusV2RegistrationImpl reg = new DatabusV2RegistrationImpl(regId, this, getCheckpointPersistenceProvider());
    List<DatabusCombinedConsumer> consumers = new ArrayList<DatabusCombinedConsumer>();
    consumers.add(consumer);
    reg.addDatabusConsumers(consumers);
    reg.addSubscriptions(sources);
    _regList.add(reg);
    reg.onRegister();
    return reg;
}
Also used : RegistrationId(com.linkedin.databus.client.pub.RegistrationId) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) SelectingDatabusCombinedConsumer(com.linkedin.databus.client.consumer.SelectingDatabusCombinedConsumer) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer) DatabusV2RegistrationImpl(com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)

Example 2 with DatabusV2RegistrationImpl

use of com.linkedin.databus.client.registration.DatabusV2RegistrationImpl in project databus by linkedin.

the class SimpleFileLoggingConsumer method mainFunction.

public void mainFunction(String[] args) throws Exception {
    String[] leftOverArgs = processLocalArgs(args);
    Properties startupProps = DatabusHttpClientImpl.processCommandLineArgs(leftOverArgs);
    DatabusHttpClientImpl.Config clientConfigBuilder = new DatabusHttpClientImpl.Config();
    clientConfigBuilder.getContainer().setIdFromName(MODULE + ".localhost");
    if (_enableBootStrap) {
        clientConfigBuilder.getRuntime().getBootstrap().setEnabled(true);
    }
    ConfigLoader<DatabusHttpClientImpl.StaticConfig> configLoader = new ConfigLoader<DatabusHttpClientImpl.StaticConfig>("databus.client.", clientConfigBuilder);
    String[] sources = addSources();
    StringBuilder sourcesString = new StringBuilder();
    boolean firstSrc = true;
    for (String source : sources) {
        if (!firstSrc)
            sourcesString.append(",");
        firstSrc = false;
        sourcesString.append(source);
    }
    if (_httpPort != null) {
        startupProps.put("databus.client.container.httpPort", _httpPort);
    }
    if (_jmxServicePort != null) {
        startupProps.put("databus.client.container.jmx.jmxServicePort", _jmxServicePort);
    }
    if (_checkpointFileRootDir != null) {
        startupProps.put("databus.client.checkpointPersistence.fileSystem.rootDirectory", _checkpointFileRootDir);
    }
    DatabusHttpClientImpl.StaticConfig clientConfig = configLoader.loadConfig(startupProps);
    // set up relay
    ServerInfoBuilder relayBuilder = clientConfig.getRuntime().getRelay("1");
    relayBuilder.setName("DefaultRelay");
    if (_relayHost != null) {
        relayBuilder.setHost(_relayHost);
    }
    if (_relayPort != null) {
        relayBuilder.setPort(Integer.parseInt(_relayPort));
    }
    relayBuilder.setSources(sourcesString.toString());
    // set up bootstrap
    if (_enableBootStrap) {
        ServerInfoBuilder bootstrapBuilder = clientConfig.getRuntime().getBootstrap().getService("2");
        bootstrapBuilder.setName("DefaultBootstrapServices");
        if (_bootstrapHost != null) {
            bootstrapBuilder.setHost(_bootstrapHost);
        }
        if (_bootstrapPort != null) {
            bootstrapBuilder.setPort(Integer.parseInt(_bootstrapPort));
        }
        bootstrapBuilder.setSources(sourcesString.toString());
    }
    // handler server side filtering, can either pass a config file or set from command line
    DbusKeyCompositeFilterConfig filterConfig = createServerSideFilterConfig(_filterConfFile, startupProps);
    // set up listeners
    DatabusHttpClientImpl client = new DatabusHttpClientImpl(clientConfig);
    // dump decoded payload values and raw (undecoded) events
    DatabusFileLoggingConsumer consumer = createTypedConsumer(_valueDumpFile, _eventDumpFile);
    if (_eventPattern != null) {
        consumer.setEventPattern(_eventPattern);
    }
    DatabusRegistration reg = client.register(consumer, sources);
    if (!(reg instanceof DatabusV2RegistrationImpl)) {
        throw new RuntimeException("Unexpected type for registration Object !!");
    }
    if (null != filterConfig)
        reg.withServerSideFilter(filterConfig);
    // add pause processor
    try {
        client.getProcessorRegistry().register(ConsumerPauseRequestProcessor.COMMAND_NAME, new ConsumerPauseRequestProcessor(null, consumer));
        client.getProcessorRegistry().register(ContainerOperationProcessor.COMMAND_NAME, new ContainerOperationProcessor(null, client));
    } catch (ProcessorRegistrationConflictException e) {
        LOG.error("Failed to register " + ConsumerPauseRequestProcessor.COMMAND_NAME);
    }
    DatabusClientShutdownThread shutdownThread = new DatabusClientShutdownThread(client);
    Runtime.getRuntime().addShutdownHook(shutdownThread);
    //this should automatically start the registration
    client.startAndBlock();
}
Also used : DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) ConfigLoader(com.linkedin.databus.core.util.ConfigLoader) DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) ContainerOperationProcessor(com.linkedin.databus2.core.container.request.ContainerOperationProcessor) Properties(java.util.Properties) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder) ProcessorRegistrationConflictException(com.linkedin.databus2.core.container.request.ProcessorRegistrationConflictException) DatabusV2RegistrationImpl(com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)

Example 3 with DatabusV2RegistrationImpl

use of com.linkedin.databus.client.registration.DatabusV2RegistrationImpl in project databus by linkedin.

the class DatabusHttpClientImpl method register.

@Override
public DatabusRegistration register(Collection<DatabusCombinedConsumer> consumers, String... sources) throws DatabusClientException {
    if ((null == consumers) || (consumers.isEmpty()))
        throw new DatabusClientException("No consumer callbacks have been specified.");
    if ((null == sources) || (sources.length == 0))
        throw new DatabusClientException("Please specify Databus sources to be consumed: register(consumer, source1, source2, ...");
    RegistrationId regId = RegistrationIdGenerator.generateNewId(consumers.iterator().next().getClass().getSimpleName(), DatabusSubscription.createSubscriptionList(Arrays.asList(sources)));
    DatabusV2RegistrationImpl reg = new DatabusV2RegistrationImpl(regId, this, getCheckpointPersistenceProvider());
    reg.addDatabusConsumers(consumers);
    reg.addSubscriptions(sources);
    _regList.add(reg);
    reg.onRegister();
    return reg;
}
Also used : RegistrationId(com.linkedin.databus.client.pub.RegistrationId) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) DatabusV2RegistrationImpl(com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)

Aggregations

DatabusV2RegistrationImpl (com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)3 DatabusClientException (com.linkedin.databus.client.pub.DatabusClientException)2 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)2 DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)1 SelectingDatabusCombinedConsumer (com.linkedin.databus.client.consumer.SelectingDatabusCombinedConsumer)1 DatabusCombinedConsumer (com.linkedin.databus.client.pub.DatabusCombinedConsumer)1 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)1 ServerInfoBuilder (com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder)1 ConfigLoader (com.linkedin.databus.core.util.ConfigLoader)1 ContainerOperationProcessor (com.linkedin.databus2.core.container.request.ContainerOperationProcessor)1 ProcessorRegistrationConflictException (com.linkedin.databus2.core.container.request.ProcessorRegistrationConflictException)1 DbusKeyCompositeFilterConfig (com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1