Class EmbeddedKafkaBroker
java.lang.Object
io.smallrye.reactive.messaging.kafka.companion.test.EmbeddedKafkaBroker
- All Implemented Interfaces:
Closeable,AutoCloseable
Embedded KRaft Broker, by default listens on localhost with random broker and controller ports.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static PropertiescreateDefaultBrokerConfig(int nodeId, org.apache.kafka.common.Endpoint controller, org.apache.kafka.common.Endpoint internalEndpoint, List<org.apache.kafka.common.Endpoint> advertisedListeners) static kafka.server.KafkaRaftServercreateServer(kafka.server.KafkaConfig config) static org.apache.kafka.common.Endpointendpoint(String listener, org.apache.kafka.common.security.auth.SecurityProtocol protocol, int port) static org.apache.kafka.common.Endpointendpoint(String listener, org.apache.kafka.common.security.auth.SecurityProtocol protocol, String host, int port) static org.apache.kafka.common.Endpointendpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, int port) static org.apache.kafka.common.Endpointstatic voidformatStorage(List<String> directories, String clusterId, int nodeId, boolean ignoreFormatted) static kafka.server.KafkaConfigformatStorageFromConfig(Properties properties, String clusterId, boolean ignoreFormatted) kafka.server.KafkaConfigintbooleanstatic org.apache.kafka.common.EndpointparseEndpoint(String listenerStr) static org.apache.kafka.common.EndpointparseEndpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, String listenerStr) start()Create and start the broker.static StringtoListenerString(org.apache.kafka.common.Endpoint endpoint) withAdditionalProperties(Consumer<Properties> function) Configure properties for the broker.withAdvertisedListeners(String advertisedListeners) Configure custom listeners for the broker.withAdvertisedListeners(org.apache.kafka.common.Endpoint... endpoints) Configure custom listeners for the broker.withClusterId(String clusterId) Configure the cluster id for the broker storage dirs.withControllerPort(int port) Configure the controller port for the broker.withDeleteLogDirsOnClose(boolean deleteDirsOnClose) Configure whether log directories will be deleted on broker shutdown.withKafkaHost(String host) Configure the hostname on which the broker will listen.withKafkaPort(int port) Configure the port on which the broker will listen.withNodeId(int nodeId) Configure node id for the broker.
-
Constructor Details
-
EmbeddedKafkaBroker
public EmbeddedKafkaBroker()
-
-
Method Details
-
withNodeId
Configure node id for the broker.- Parameters:
nodeId- the node id.- Returns:
- this
EmbeddedKafkaBroker
-
withAdditionalProperties
Configure properties for the broker.- Parameters:
function- the config modifier function.- Returns:
- this
EmbeddedKafkaBroker
-
withKafkaPort
Configure the port on which the broker will listen.- Parameters:
port- the port.- Returns:
- this
EmbeddedKafkaBroker
-
withControllerPort
Configure the controller port for the broker.- Parameters:
port- the port.- Returns:
- this
EmbeddedKafkaBroker
-
withKafkaHost
Configure the hostname on which the broker will listen.- Parameters:
host- the host.- Returns:
- this
EmbeddedKafkaBroker
-
withClusterId
Configure the cluster id for the broker storage dirs.- Parameters:
clusterId- the cluster id.- Returns:
- this
EmbeddedKafkaBroker
-
withDeleteLogDirsOnClose
Configure whether log directories will be deleted on broker shutdown.- Parameters:
deleteDirsOnClose-true- Returns:
- this
EmbeddedKafkaBroker
-
withAdvertisedListeners
Configure custom listeners for the broker.Note that this will override the default PLAINTEXT listener. A CONTROLLER listener will be added automatically.
- Returns:
- this
EmbeddedKafkaBroker
-
withAdvertisedListeners
Configure custom listeners for the broker.Note that this will override the default PLAINTEXT listener. A CONTROLLER listener will be added automatically.
- Returns:
- this
EmbeddedKafkaBroker
-
start
Create and start the broker.- Returns:
- this
EmbeddedKafkaBroker
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isRunning
public boolean isRunning() -
getKafkaConfig
public kafka.server.KafkaConfig getKafkaConfig() -
getAdvertisedListeners
-
getLogDirs
-
getNodeId
public int getNodeId() -
getClusterId
-
endpoint
public static org.apache.kafka.common.Endpoint endpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, int port) -
endpoint
public static org.apache.kafka.common.Endpoint endpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, String host, int port) -
endpoint
public static org.apache.kafka.common.Endpoint endpoint(String listener, org.apache.kafka.common.security.auth.SecurityProtocol protocol, int port) -
endpoint
-
parseEndpoint
public static org.apache.kafka.common.Endpoint parseEndpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, String listenerStr) -
parseEndpoint
-
createDefaultBrokerConfig
public static Properties createDefaultBrokerConfig(int nodeId, org.apache.kafka.common.Endpoint controller, org.apache.kafka.common.Endpoint internalEndpoint, List<org.apache.kafka.common.Endpoint> advertisedListeners) -
formatStorageFromConfig
public static kafka.server.KafkaConfig formatStorageFromConfig(Properties properties, String clusterId, boolean ignoreFormatted) -
formatStorage
-
createServer
public static kafka.server.KafkaRaftServer createServer(kafka.server.KafkaConfig config) -
toListenerString
-