Search in sources :

Example 1 with FileOffsetBackingStore

use of org.apache.kafka.connect.storage.FileOffsetBackingStore in project kafka by apache.

the class ConnectStandalone method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        log.info("Usage: ConnectStandalone worker.properties connector1.properties [connector2.properties ...]");
        Exit.exit(1);
    }
    String workerPropsFile = args[0];
    Map<String, String> workerProps = !workerPropsFile.isEmpty() ? Utils.propsToStringMap(Utils.loadProps(workerPropsFile)) : Collections.<String, String>emptyMap();
    Time time = Time.SYSTEM;
    ConnectorFactory connectorFactory = new ConnectorFactory();
    StandaloneConfig config = new StandaloneConfig(workerProps);
    RestServer rest = new RestServer(config);
    URI advertisedUrl = rest.advertisedUrl();
    String workerId = advertisedUrl.getHost() + ":" + advertisedUrl.getPort();
    Worker worker = new Worker(workerId, time, connectorFactory, config, new FileOffsetBackingStore());
    Herder herder = new StandaloneHerder(worker);
    final Connect connect = new Connect(herder, rest);
    try {
        connect.start();
        for (final String connectorPropsFile : Arrays.copyOfRange(args, 1, args.length)) {
            Map<String, String> connectorProps = Utils.propsToStringMap(Utils.loadProps(connectorPropsFile));
            FutureCallback<Herder.Created<ConnectorInfo>> cb = new FutureCallback<>(new Callback<Herder.Created<ConnectorInfo>>() {

                @Override
                public void onCompletion(Throwable error, Herder.Created<ConnectorInfo> info) {
                    if (error != null)
                        log.error("Failed to create job for {}", connectorPropsFile);
                    else
                        log.info("Created connector {}", info.result().name());
                }
            });
            herder.putConnectorConfig(connectorProps.get(ConnectorConfig.NAME_CONFIG), connectorProps, false, cb);
            cb.get();
        }
    } catch (Throwable t) {
        log.error("Stopping after connector error", t);
        connect.stop();
    }
    // Shutdown will be triggered by Ctrl-C or via HTTP shutdown request
    connect.awaitStop();
}
Also used : ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) Connect(org.apache.kafka.connect.runtime.Connect) Time(org.apache.kafka.common.utils.Time) URI(java.net.URI) FileOffsetBackingStore(org.apache.kafka.connect.storage.FileOffsetBackingStore) RestServer(org.apache.kafka.connect.runtime.rest.RestServer) ConnectorFactory(org.apache.kafka.connect.runtime.ConnectorFactory) StandaloneHerder(org.apache.kafka.connect.runtime.standalone.StandaloneHerder) Worker(org.apache.kafka.connect.runtime.Worker) StandaloneConfig(org.apache.kafka.connect.runtime.standalone.StandaloneConfig) Herder(org.apache.kafka.connect.runtime.Herder) StandaloneHerder(org.apache.kafka.connect.runtime.standalone.StandaloneHerder) FutureCallback(org.apache.kafka.connect.util.FutureCallback)

Aggregations

URI (java.net.URI)1 Time (org.apache.kafka.common.utils.Time)1 Connect (org.apache.kafka.connect.runtime.Connect)1 ConnectorFactory (org.apache.kafka.connect.runtime.ConnectorFactory)1 Herder (org.apache.kafka.connect.runtime.Herder)1 Worker (org.apache.kafka.connect.runtime.Worker)1 RestServer (org.apache.kafka.connect.runtime.rest.RestServer)1 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)1 StandaloneConfig (org.apache.kafka.connect.runtime.standalone.StandaloneConfig)1 StandaloneHerder (org.apache.kafka.connect.runtime.standalone.StandaloneHerder)1 FileOffsetBackingStore (org.apache.kafka.connect.storage.FileOffsetBackingStore)1 FutureCallback (org.apache.kafka.connect.util.FutureCallback)1