Search in sources :

Example 1 with DatabusEventProducer

use of com.linkedin.databus.core.util.DatabusEventProducer in project databus by linkedin.

the class TestRelayCommandsLocal method setUp.

@BeforeMethod
public void setUp() throws Exception {
    // creates an event factory for us
    _relay = new HttpRelay(_staticConfig, null);
    _eventBuffer = _relay.getEventBuffer();
    DatabusEventProducer randomEventProducer = new DatabusEventRandomProducer(_eventBuffer, 10, 1, 10, _staticConfig.getSourceIds(), null, null);
    RequestProcessorRegistry processorRegistry = _relay.getProcessorRegistry();
    processorRegistry.register(EchoRequestProcessor.COMMAND_NAME, new EchoRequestProcessor(null));
    processorRegistry.register(GenerateDataEventsRequestProcessor.COMMAND_NAME, new GenerateDataEventsRequestProcessor(null, _relay, randomEventProducer));
    // Configure the server.
    _bootstrap = new ServerBootstrap(new DefaultLocalServerChannelFactory());
    // Set up the event pipeline factory.
    _bootstrap.setPipelineFactory(new HttpServerPipelineFactory(_relay));
    _serverAddress = new LocalAddress(10);
    _serverChannel = _bootstrap.bind(_serverAddress);
}
Also used : DatabusEventRandomProducer(com.linkedin.databus.core.util.DatabusEventRandomProducer) HttpServerPipelineFactory(com.linkedin.databus2.core.container.netty.HttpServerPipelineFactory) EchoRequestProcessor(com.linkedin.databus2.core.container.request.EchoRequestProcessor) DefaultLocalServerChannelFactory(org.jboss.netty.channel.local.DefaultLocalServerChannelFactory) LocalAddress(org.jboss.netty.channel.local.LocalAddress) RequestProcessorRegistry(com.linkedin.databus2.core.container.request.RequestProcessorRegistry) DatabusEventProducer(com.linkedin.databus.core.util.DatabusEventProducer) GenerateDataEventsRequestProcessor(com.linkedin.databus.container.request.GenerateDataEventsRequestProcessor) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with DatabusEventProducer

use of com.linkedin.databus.core.util.DatabusEventProducer in project databus by linkedin.

the class HttpRelay method main.

public static void main(String[] args) throws Exception {
    Cli cli = new Cli();
    cli.processCommandLineArgs(args);
    cli.parseRelayConfig();
    StaticConfig staticConfig = cli.getRelayConfigBuilder().build();
    HttpRelay relay = new HttpRelay(staticConfig, cli.getPhysicalSourceStaticConfigs());
    RequestProcessorRegistry processorRegistry = relay.getProcessorRegistry();
    // Changes to add schemaId to event; DDSDBUS-3421
    // The long term fix is to remove DatabusEventRandomProducer in favour of RelayEventGenerator
    // The medium term fix is to send SchemaRegistry to DatabusEventRandomProducer, but move RandomProducer to databus-relay-impl (from databus-core-impl)
    // Reason: SchemaHelper classes required to parse/generate schemaId from schemaRegistry requires databus-schemas-core which depends on databus-core-impl
    SchemaRegistryService sr = relay.getSchemaRegistryService();
    HashMap<Long, byte[]> schemaIds = new HashMap<Long, byte[]>(staticConfig.getSourceIds().size());
    for (IdNamePair pair : staticConfig.getSourceIds()) {
        LOG.info("Http Relay Schema Reg:" + pair.getName() + " id=" + pair.getId());
        String schemaStr = sr.fetchLatestSchemaBySourceName(pair.getName());
        if (schemaStr != null) {
            Schema s = Schema.parse(schemaStr);
            byte[] sid = SchemaHelper.getSchemaId(s.toString());
            LOG.info("Found schema! Adding schemaId for sourceName=" + pair.getName() + " id=" + pair.getId() + " schemaId=" + sid);
            schemaIds.put(pair.getId(), sid);
        } else {
            byte[] defaultSid = "abcde".getBytes(Charset.defaultCharset());
            LOG.info("Didn't find schema! Adding default schemaId for sourceName=" + pair.getName() + "id=" + pair.getId() + " schemaId=" + defaultSid);
            schemaIds.put(pair.getId(), defaultSid);
        }
    }
    DatabusEventProducer randomEventProducer = new DatabusEventRandomProducer(relay.getEventBuffer(), 10, 100, 1000, staticConfig.getSourceIds(), schemaIds);
    // specify stats collector for this producer
    ((DatabusEventRandomProducer) randomEventProducer).setStatsCollector(relay.getInboundEventStatisticsCollector());
    processorRegistry.register(EchoRequestProcessor.COMMAND_NAME, new EchoRequestProcessor(null));
    processorRegistry.register(SleepRequestProcessor.COMMAND_NAME, new SleepRequestProcessor(null));
    processorRegistry.register(GenerateDataEventsRequestProcessor.COMMAND_NAME, new GenerateDataEventsRequestProcessor(null, relay, randomEventProducer));
    processorRegistry.register(LoadDataEventsRequestProcessor.COMMAND_NAME, new LoadDataEventsRequestProcessor(relay.getDefaultExecutorService(), relay));
    LOG.info("source = " + relay.getSourcesIdNameRegistry().getAllSources());
    try {
        relay.registerShutdownHook();
        relay.startAndBlock();
    } catch (Exception e) {
        LOG.error("Error starting the relay", e);
    }
    LOG.info("Exiting relay");
}
Also used : DatabusEventRandomProducer(com.linkedin.databus.core.util.DatabusEventRandomProducer) EchoRequestProcessor(com.linkedin.databus2.core.container.request.EchoRequestProcessor) LoadDataEventsRequestProcessor(com.linkedin.databus.container.request.LoadDataEventsRequestProcessor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FileSystemSchemaRegistryService(com.linkedin.databus2.schemas.FileSystemSchemaRegistryService) SchemaRegistryService(com.linkedin.databus2.schemas.SchemaRegistryService) Schema(org.apache.avro.Schema) DataSourcesStaticConfig(com.linkedin.databus2.relay.config.DataSourcesStaticConfig) SchemaRegistryStaticConfig(com.linkedin.databus2.schemas.SchemaRegistryStaticConfig) PhysicalSourceStaticConfig(com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig) SleepRequestProcessor(com.linkedin.databus2.core.container.request.SleepRequestProcessor) BufferNotFoundException(com.linkedin.databus2.core.BufferNotFoundException) DatabusException(com.linkedin.databus2.core.DatabusException) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) UnsupportedKeyException(com.linkedin.databus.core.UnsupportedKeyException) SQLException(java.sql.SQLException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) EventCreationException(com.linkedin.databus2.producers.EventCreationException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) RequestProcessorRegistry(com.linkedin.databus2.core.container.request.RequestProcessorRegistry) IdNamePair(com.linkedin.databus.core.util.IdNamePair) DatabusEventProducer(com.linkedin.databus.core.util.DatabusEventProducer) GenerateDataEventsRequestProcessor(com.linkedin.databus.container.request.GenerateDataEventsRequestProcessor)

Aggregations

GenerateDataEventsRequestProcessor (com.linkedin.databus.container.request.GenerateDataEventsRequestProcessor)2 DatabusEventProducer (com.linkedin.databus.core.util.DatabusEventProducer)2 DatabusEventRandomProducer (com.linkedin.databus.core.util.DatabusEventRandomProducer)2 EchoRequestProcessor (com.linkedin.databus2.core.container.request.EchoRequestProcessor)2 RequestProcessorRegistry (com.linkedin.databus2.core.container.request.RequestProcessorRegistry)2 LoadDataEventsRequestProcessor (com.linkedin.databus.container.request.LoadDataEventsRequestProcessor)1 UnsupportedKeyException (com.linkedin.databus.core.UnsupportedKeyException)1 IdNamePair (com.linkedin.databus.core.util.IdNamePair)1 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)1 BufferNotFoundException (com.linkedin.databus2.core.BufferNotFoundException)1 DatabusException (com.linkedin.databus2.core.DatabusException)1 HttpServerPipelineFactory (com.linkedin.databus2.core.container.netty.HttpServerPipelineFactory)1 SleepRequestProcessor (com.linkedin.databus2.core.container.request.SleepRequestProcessor)1 EventCreationException (com.linkedin.databus2.producers.EventCreationException)1 DataSourcesStaticConfig (com.linkedin.databus2.relay.config.DataSourcesStaticConfig)1 PhysicalSourceStaticConfig (com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig)1 FileSystemSchemaRegistryService (com.linkedin.databus2.schemas.FileSystemSchemaRegistryService)1 SchemaRegistryService (com.linkedin.databus2.schemas.SchemaRegistryService)1 SchemaRegistryStaticConfig (com.linkedin.databus2.schemas.SchemaRegistryStaticConfig)1 IOException (java.io.IOException)1