本文整理汇总了Java中kafka.utils.TestUtils.createServer方法的典型用法代码示例。如果您正苦于以下问题:Java TestUtils.createServer方法的具体用法?Java TestUtils.createServer怎么用?Java TestUtils.createServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kafka.utils.TestUtils
的用法示例。
在下文中一共展示了TestUtils.createServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startup
import kafka.utils.TestUtils; //导入方法依赖的package包/类
/**
* Starts the Embedded Kafka and Zookeeper Servers.
* @throws Exception - If an exeption occurs during startup.
*/
protected void startup() throws Exception {
// Setup the embedded zookeeper
logger.info("Starting up Embedded Zookeeper...");
zkServer = new EmbeddedZookeeper();
zookeperConnect = ZKHOST + ":" + zkServer.port();
logger.info("Embedded Zookeeper started at: {}", zookeperConnect);
// setup Broker
logger.info("Starting up Embedded Kafka...");
brokerPort = Integer.toString(PortUtils.getRandomFreePort());
final Properties brokerProps = new Properties();
brokerProps.setProperty(KafkaConfig$.MODULE$.BrokerIdProp(), "0");
brokerProps.setProperty(KafkaConfig$.MODULE$.HostNameProp(), BROKERHOST);
brokerProps.setProperty(KafkaConfig$.MODULE$.PortProp(), brokerPort);
brokerProps.setProperty(KafkaConfig$.MODULE$.ZkConnectProp(), zookeperConnect);
brokerProps.setProperty(KafkaConfig$.MODULE$.LogDirsProp(), Files.createTempDirectory(getClass().getSimpleName() + "-").toAbsolutePath().toString());
final KafkaConfig config = new KafkaConfig(brokerProps);
final Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
logger.info("Embedded Kafka Server started at: {}:{}", BROKERHOST, brokerPort);
}
示例2: setupKafka
import kafka.utils.TestUtils; //导入方法依赖的package包/类
/**
* setup mini kafka and call the super to setup mini fluo
*/
@Before
public void setupKafka() throws Exception {
// Install an instance of Rya on the Accumulo cluster.
installRyaInstance();
// Setup Kafka.
zkServer = new EmbeddedZookeeper();
final String zkConnect = ZKHOST + ":" + zkServer.port();
zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
zkUtils = ZkUtils.apply(zkClient, false);
// setup Broker
final Properties brokerProps = new Properties();
brokerProps.setProperty("zookeeper.connect", zkConnect);
brokerProps.setProperty("broker.id", "0");
brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
final KafkaConfig config = new KafkaConfig(brokerProps);
final Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
}
示例3: startServer
import kafka.utils.TestUtils; //导入方法依赖的package包/类
public static void startServer() throws RuntimeException {
if (serverStarted && serverClosed) {
throw new RuntimeException("Kafka test server has already been closed. Cannot generate Kafka server twice.");
}
if (!serverStarted) {
serverStarted = true;
zkConnect = TestZKUtils.zookeeperConnect();
zkServer = new EmbeddedZookeeper(zkConnect);
zkClient = new ZkClient(zkServer.connectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
kafkaPort = TestUtils.choosePort();
Properties props = TestUtils.createBrokerConfig(brokerId, kafkaPort, true);
KafkaConfig config = new KafkaConfig(props);
Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
}
}
示例4: KafkaEmbedded
import kafka.utils.TestUtils; //导入方法依赖的package包/类
/**
* Creates and starts an embedded Kafka broker.
*
* @param config Broker configuration settings. Used to modify, for example, on which port the
* broker should listen to. Note that you cannot change the `log.dirs` setting
* currently.
*/
public KafkaEmbedded(final Properties config, final MockTime time) throws IOException {
tmpFolder = new TemporaryFolder();
tmpFolder.create();
logDir = tmpFolder.newFolder();
effectiveConfig = effectiveConfigFrom(config);
final boolean loggingEnabled = true;
final KafkaConfig kafkaConfig = new KafkaConfig(effectiveConfig, loggingEnabled);
log.debug("Starting embedded Kafka broker (with log.dirs={} and ZK ensemble at {}) ...",
logDir, zookeeperConnect());
kafka = TestUtils.createServer(kafkaConfig, time);
log.debug("Startup of embedded Kafka broker at {} completed (with ZK ensemble at {}) ...",
brokerList(), zookeeperConnect());
}
示例5: KafkaEmbedded
import kafka.utils.TestUtils; //导入方法依赖的package包/类
/**
* Creates and starts an embedded Kafka broker.
*
* @param config Broker configuration settings. Used to modify, for example, on which port the
* broker should listen to. Note that you cannot change some settings such as
* `log.dirs`, `port`.
*/
public KafkaEmbedded(Properties config) throws IOException {
tmpFolder = new TemporaryFolder();
tmpFolder.create();
logDir = tmpFolder.newFolder();
effectiveConfig = effectiveConfigFrom(config);
boolean loggingEnabled = true;
KafkaConfig kafkaConfig = new KafkaConfig(effectiveConfig, loggingEnabled);
log.debug("Starting embedded Kafka broker (with log.dirs={} and ZK ensemble at {}) ...",
logDir, zookeeperConnect());
kafka = TestUtils.createServer(kafkaConfig, Time.SYSTEM);
log.debug("Startup of embedded Kafka broker at {} completed (with ZK ensemble at {}) ...",
brokerList(), zookeeperConnect());
}
示例6: setup
import kafka.utils.TestUtils; //导入方法依赖的package包/类
@BeforeClass
public static void setup() {
zkServer = new EmbeddedZookeeper(TestZKUtils.zookeeperConnect());
zkClient = new ZkClient(zkServer.connectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
kafkaServer = TestUtils.createServer(new KafkaConfig(TestUtils.createBrokerConfig(0, brokerPort, true)),
new MockTime());
kafkaServers = new ArrayList<>();
kafkaServers.add(kafkaServer);
}
示例7: KafkaEmbedded
import kafka.utils.TestUtils; //导入方法依赖的package包/类
/**
* Creates and starts an embedded Kafka broker.
*
* @param config Broker configuration settings. Used to modify, for example, on which port the
* broker should listen to. Note that you cannot change the `log.dirs` setting
* currently.
*/
public KafkaEmbedded(final Properties config, final MockTime time) throws IOException {
tmpFolder = new TemporaryFolder();
tmpFolder.create();
logDir = tmpFolder.newFolder();
effectiveConfig = effectiveConfigFrom(config);
final boolean loggingEnabled = true;
final KafkaConfig kafkaConfig = new KafkaConfig(effectiveConfig, loggingEnabled);
log.debug("Starting embedded Kafka broker (with log.dirs={} and ZK ensemble at {}) ...",
logDir, zookeeperConnect());
kafka = TestUtils.createServer(kafkaConfig, time);
log.debug("Startup of embedded Kafka broker at {} completed (with ZK ensemble at {}) ...",
brokerList(), zookeeperConnect());
}
示例8: KafkaEmbedded
import kafka.utils.TestUtils; //导入方法依赖的package包/类
/**
* Creates and starts an embedded Kafka broker.
*
* @param config Broker configuration settings. Used to modify, for example, on which port the
* broker should listen to. Note that you cannot change some settings such as
* `log.dirs`, `port`.
*/
public KafkaEmbedded(Properties config) throws IOException {
tmpFolder = new TemporaryFolder();
tmpFolder.create();
logDir = tmpFolder.newFolder();
effectiveConfig = effectiveConfigFrom(config);
boolean loggingEnabled = true;
KafkaConfig kafkaConfig = new KafkaConfig(effectiveConfig, loggingEnabled);
log.debug("Starting embedded Kafka broker (with log.dirs={} and ZK ensemble at {}) ...",
logDir, zookeeperConnect());
kafka = TestUtils.createServer(kafkaConfig, new SystemTime());
log.debug("Startup of embedded Kafka broker at {} completed (with ZK ensemble at {}) ...",
brokerList(), zookeeperConnect());
}
示例9: setupKafkaServer
import kafka.utils.TestUtils; //导入方法依赖的package包/类
/**
* Sets up test Kafka broker.
*
* @throws IOException If failed.
*/
private void setupKafkaServer() throws IOException {
kafkaCfg = new KafkaConfig(getKafkaConfig());
kafkaSrv = TestUtils.createServer(kafkaCfg, SystemTime$.MODULE$);
kafkaSrv.startup();
}
示例10: createKafkaServer
import kafka.utils.TestUtils; //导入方法依赖的package包/类
public static KafkaServer createKafkaServer(int brokerId, int port, String zkConnect) {
final Option<File> noFile = scala.Option.apply(null);
final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option.apply(null);
// new params for kafka 0.10.0
Option<Properties> saslProperties = scala.Option.apply(null);
Option rack = scala.Option.apply(RackAwareMode.Enforced$.MODULE$.toString());
Properties props = TestUtils.createBrokerConfig(
brokerId,
zkConnect,
false,
false,
port,
noInterBrokerSecurityProtocol,
noFile,
saslProperties,
true,
false,
TestUtils.RandomPort(),
false,
TestUtils.RandomPort(),
false,
TestUtils.RandomPort(),
rack
);
props.setProperty("auto.create.topics.enable", "true");
props.setProperty("num.partitions", "1");
props.setProperty("zookeeper.connect", zkConnect);
KafkaConfig config = new KafkaConfig(props);
return TestUtils.createServer(config, Time.SYSTEM);
}
示例11: createKafkaServer
import kafka.utils.TestUtils; //导入方法依赖的package包/类
public static KafkaServer createKafkaServer(int brokerId, int port, String zkConnect) {
final Option<File> noFile = scala.Option.apply(null);
final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option.apply(null);
// new params for kafka 0.10.0
Option<Properties> saslProperties = scala.Option.apply(null);
Option rack = scala.Option.apply(RackAwareMode.Enforced$.MODULE$.toString());
Properties props = TestUtils.createBrokerConfig(
brokerId,
zkConnect,
false,
false,
port,
noInterBrokerSecurityProtocol,
noFile,
saslProperties,
true,
false,
TestUtils.RandomPort(),
false,
TestUtils.RandomPort(),
false,
TestUtils.RandomPort(),
rack
);
props.setProperty("auto.create.topics.enable", "true");
props.setProperty("num.partitions", "1");
props.setProperty("zookeeper.connect", zkConnect);
KafkaConfig config = new KafkaConfig(props);
return TestUtils.createServer(config, SystemTime$.MODULE$);
}
示例12: createKafkaServer
import kafka.utils.TestUtils; //导入方法依赖的package包/类
public static KafkaServer createKafkaServer(int brokerId, int port, String zkConnect) {
final Option<File> noFile = scala.Option.apply(null);
final Option<SecurityProtocol> noInterBrokerSecurityProtocol = scala.Option.apply(null);
// new params for kafka 0.10.0
Option<Properties> saslProperties = scala.Option.apply(null);
Option rack = scala.Option.apply(RackAwareMode.Enforced$.MODULE$.toString());
Properties props = TestUtils.createBrokerConfig(
brokerId,
zkConnect,
false,
false,
port,
noInterBrokerSecurityProtocol,
noFile,
saslProperties,
true,
false,
TestUtils.RandomPort(),
false,
TestUtils.RandomPort(),
false,
TestUtils.RandomPort(),
rack,
1
);
props.setProperty("auto.create.topics.enable", "true");
props.setProperty("num.partitions", "1");
props.setProperty("zookeeper.connect", zkConnect);
KafkaConfig config = new KafkaConfig(props);
return TestUtils.createServer(config, Time.SYSTEM);
}
示例13: startKafkaServer
import kafka.utils.TestUtils; //导入方法依赖的package包/类
private KafkaServer startKafkaServer() {
Properties props = TestUtils.createBrokerConfig(0, zookeeper.getConnectString(), true, true, 9092, Option.<SecurityProtocol>empty(), Option.<File>empty(), Option.<Properties>empty(), true, false, 0, false, 0, false, 0, Option.<String>empty(), 0);
props.put(KafkaConfig.ZkConnectProp(), zookeeper.getConnectString());
kafkaServer = TestUtils.createServer(new KafkaConfig(props), new kafka.utils.MockTime());
return kafkaServer;
}
示例14: createKafkaServer
import kafka.utils.TestUtils; //导入方法依赖的package包/类
public static KafkaServer createKafkaServer(int port, String zkConnect, boolean autoCreateTopic) {
KafkaConfig config = new KafkaConfig(createKafkaConfig(port, zkConnect, autoCreateTopic, 1));
return TestUtils.createServer(config, Time.SYSTEM);
}
示例15: before
import kafka.utils.TestUtils; //导入方法依赖的package包/类
@Before
public void before() {
zkServer = new EmbeddedZookeeper();
zkConnect = String.format("localhost:%d", zkServer.port());
ZkUtils zkUtils = ZkUtils.apply(zkConnect, 30000, 30000,
JaasUtils.isZkSecurityEnabled());
zkClient = zkUtils.zkClient();
final Option<java.io.File> noFile = Option.apply(null);
final Option<SecurityProtocol> noInterBrokerSecurityProtocol = Option
.apply(null);
kafkaProps = TestUtils.createBrokerConfig(brokerId, zkConnect, false,
false, port, noInterBrokerSecurityProtocol, noFile, true,
false, TestUtils.RandomPort(), false, TestUtils.RandomPort(),
false, TestUtils.RandomPort());
kafkaProps.setProperty("auto.create.topics.enable", "true");
kafkaProps.setProperty("num.partitions", "1");
// We *must* override this to use the port we allocated (Kafka currently
// allocates one port
// that it always uses for ZK
kafkaProps.setProperty("zookeeper.connect", this.zkConnect);
kafkaProps.setProperty("host.name", "localhost");
kafkaProps.setProperty("port", port + "");
KafkaConfig config = new KafkaConfig(kafkaProps);
Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
// create topic
TopicCommand.TopicCommandOptions options = new TopicCommand.TopicCommandOptions(
new String[]{"--create", "--topic", topic,
"--replication-factor", "1", "--partitions", "1"});
TopicCommand.createTopic(zkUtils, options);
List<KafkaServer> servers = new ArrayList<KafkaServer>();
servers.add(kafkaServer);
TestUtils.waitUntilMetadataIsPropagated(
scala.collection.JavaConversions.asScalaBuffer(servers), topic,
0, 5000);
}