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

com.zaradai.gluon.server.KafkaServer Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2016 Zaradai
 * 

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.zaradai.gluon.server; import com.google.common.eventbus.EventBus; import com.zaradai.gluon.codecs.FstCodec; import com.zaradai.gluon.kafka.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static com.google.common.base.Preconditions.checkNotNull; public class KafkaServer extends BaseServer { private static final Logger LOG = LoggerFactory.getLogger(KafkaServer.class); static final String SERVER_BUS_ID = "server"; static final String SERVER_GROUP = "Server-Group"; private final KafkaServerEventAdaptor eventAdaptor; public KafkaServer(KafkaConfig config) { this(config, new DefaultProducerFactory(), new DefaultConsumerFactory()); } public KafkaServer(KafkaConfig config, ProducerFactory producerFactory, ConsumerFactory consumerFactory) { super(new EventBus(SERVER_BUS_ID)); checkNotNull(config, "Invalid config."); // ensure we set the group ID config.getConsumerConfig().setGroupId(SERVER_GROUP); // adapt the server event bus using kafka messages eventAdaptor = new KafkaServerEventAdaptor(getEventBus(), new FstCodec(), config, producerFactory, consumerFactory); } @Override protected void startUp() throws Exception { super.startUp(); eventAdaptor.startAsync().awaitRunning(); LOG.debug("Kafka server started."); } @Override protected void shutDown() throws Exception { super.shutDown(); eventAdaptor.stopAsync().awaitTerminated(); LOG.debug("Kafka server shutdown."); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy