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