Class EmbeddedKafkaBroker
- java.lang.Object
-
- io.smallrye.reactive.messaging.kafka.companion.test.EmbeddedKafkaBroker
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class EmbeddedKafkaBroker extends Object implements Closeable
Embedded KRaft Broker, by default listens on localhost with random broker and controller ports.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEmbeddedKafkaBroker.LoggingOutputStream
-
Constructor Summary
Constructors Constructor Description EmbeddedKafkaBroker()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()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.Endpointendpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, String host, int port)static voidformatStorage(List<String> directories, String clusterId, int nodeId, boolean ignoreFormatted)static kafka.server.KafkaConfigformatStorageFromConfig(Properties properties, String clusterId, boolean ignoreFormatted)StringgetAdvertisedListeners()StringgetClusterId()kafka.server.KafkaConfiggetKafkaConfig()List<String>getLogDirs()intgetNodeId()booleanisRunning()static org.apache.kafka.common.EndpointparseEndpoint(String listenerStr)static org.apache.kafka.common.EndpointparseEndpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, String listenerStr)EmbeddedKafkaBrokerstart()Create and start the broker.static StringtoListenerString(org.apache.kafka.common.Endpoint endpoint)EmbeddedKafkaBrokerwithAdditionalProperties(Consumer<Properties> function)Configure properties for the broker.EmbeddedKafkaBrokerwithAdvertisedListeners(String advertisedListeners)Configure custom listeners for the broker.EmbeddedKafkaBrokerwithAdvertisedListeners(org.apache.kafka.common.Endpoint... endpoints)Configure custom listeners for the broker.EmbeddedKafkaBrokerwithClusterId(String clusterId)Configure the cluster id for the broker storage dirs.EmbeddedKafkaBrokerwithControllerPort(int port)Configure the controller port for the broker.EmbeddedKafkaBrokerwithDeleteLogDirsOnClose(boolean deleteDirsOnClose)Configure whether log directories will be deleted on broker shutdown.EmbeddedKafkaBrokerwithKafkaHost(String host)Configure the hostname on which the broker will listen.EmbeddedKafkaBrokerwithKafkaPort(int port)Configure the port on which the broker will listen.EmbeddedKafkaBrokerwithNodeId(int nodeId)Configure node id for the broker.
-
-
-
Method Detail
-
withNodeId
public EmbeddedKafkaBroker withNodeId(int nodeId)
Configure node id for the broker.- Parameters:
nodeId- the node id.- Returns:
- this
EmbeddedKafkaBroker
-
withAdditionalProperties
public EmbeddedKafkaBroker withAdditionalProperties(Consumer<Properties> function)
Configure properties for the broker.- Parameters:
function- the config modifier function.- Returns:
- this
EmbeddedKafkaBroker
-
withKafkaPort
public EmbeddedKafkaBroker withKafkaPort(int port)
Configure the port on which the broker will listen.- Parameters:
port- the port.- Returns:
- this
EmbeddedKafkaBroker
-
withControllerPort
public EmbeddedKafkaBroker withControllerPort(int port)
Configure the controller port for the broker.- Parameters:
port- the port.- Returns:
- this
EmbeddedKafkaBroker
-
withKafkaHost
public EmbeddedKafkaBroker withKafkaHost(String host)
Configure the hostname on which the broker will listen.- Parameters:
host- the host.- Returns:
- this
EmbeddedKafkaBroker
-
withClusterId
public EmbeddedKafkaBroker withClusterId(String clusterId)
Configure the cluster id for the broker storage dirs.- Parameters:
clusterId- the cluster id.- Returns:
- this
EmbeddedKafkaBroker
-
withDeleteLogDirsOnClose
public EmbeddedKafkaBroker withDeleteLogDirsOnClose(boolean deleteDirsOnClose)
Configure whether log directories will be deleted on broker shutdown.- Parameters:
deleteDirsOnClose-true- Returns:
- this
EmbeddedKafkaBroker
-
withAdvertisedListeners
public EmbeddedKafkaBroker withAdvertisedListeners(org.apache.kafka.common.Endpoint... endpoints)
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
public EmbeddedKafkaBroker withAdvertisedListeners(String advertisedListeners)
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
public 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
public String getAdvertisedListeners()
-
getNodeId
public int getNodeId()
-
getClusterId
public String 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
public static org.apache.kafka.common.Endpoint endpoint(String listener, org.apache.kafka.common.security.auth.SecurityProtocol protocol, String host, int port)
-
parseEndpoint
public static org.apache.kafka.common.Endpoint parseEndpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, String listenerStr)
-
parseEndpoint
public static org.apache.kafka.common.Endpoint parseEndpoint(String listenerStr)
-
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
public static void formatStorage(List<String> directories, String clusterId, int nodeId, boolean ignoreFormatted)
-
createServer
public static kafka.server.KafkaRaftServer createServer(kafka.server.KafkaConfig config)
-
toListenerString
public static String toListenerString(org.apache.kafka.common.Endpoint endpoint)
-
-