All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.continual.services.rcvr.ReceiverApiService Maven / Gradle / Ivy

Go to download

The Continual.io event receiver API, which ingests event streams from arbitrary client sources, honors ordering in the event stream via event stream name (aka partition key), and writes to a back-end implementation like Kafka.

There is a newer version: 0.3.23
Show newest version
package io.continual.services.rcvr;

import java.io.IOException;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.continual.builder.Builder.BuildFailure;
import io.continual.http.service.framework.routing.CHttpRequestRouter;
import io.continual.http.service.framework.routing.playish.CHttpPlayishInstanceCallRoutingSource;
import io.continual.iam.identity.Identity;
import io.continual.resources.ResourceLoader;
import io.continual.restHttp.BaseApiServiceRouter;
import io.continual.restHttp.HttpService;
import io.continual.restHttp.HttpServlet;
import io.continual.services.ServiceContainer;
import io.continual.services.SimpleService;
import io.continual.util.nv.NvReadable;

public class ReceiverApiService extends SimpleService
{
	public ReceiverApiService ( ServiceContainer sc, JSONObject config ) throws BuildFailure
	{
		final HttpService server = sc.get ( config.optString ( "httpService", "httpService" ), HttpService.class );
		server.addRouter (
			"rcvrApi",
			new BaseApiServiceRouter ()
			{
				@Override
				public void setupRouter ( HttpServlet servlet, CHttpRequestRouter rr, NvReadable p ) throws IOException, BuildFailure
				{
					super.setupExceptionHandlers ( servlet, rr, p );

					// setup routes
					for ( String routeFile : new String[]
						{
							"rcvrRoutes.conf"
						} )
					{
						log.debug ( "Loading routes from " + routeFile );
						rr.addRouteSource ( new CHttpPlayishInstanceCallRoutingSource> (
							new ReceiverApi ( sc, config ),
							ResourceLoader.load ( routeFile ) )
						);
					}
				}
			}
		);
	}

	private static final Logger log = LoggerFactory.getLogger ( ReceiverApiService.class );
}