use of com.linkedin.databus2.core.container.request.SleepRequestProcessor 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");
}
Aggregations