io.jstach.rainbowgum.rabbitmq.RabbitMQOutputBuilder Maven / Gradle / Ivy
The newest version!
package io.jstach.rainbowgum.rabbitmq;
import io.jstach.rainbowgum.LogProperties;
import io.jstach.rainbowgum.LogProperty;
import io.jstach.rainbowgum.LogProperty.Property;
/**
* Builder to create {@link io.jstach.rainbowgum.rabbitmq.RabbitMQOutput }.
* Creates a RabbitMQOutput.
*
* Properties retrieved from LogProperties
*
* Property Pattern
* Type
* Required
* Default
* Description
*
*
* {@value PROPERTY_uri }
* URI
* false
* null
* Passed to the rabbitmq connection factory.
*
*
* {@value PROPERTY_exchange }
* String
* true
* {@value io.jstach.rainbowgum.rabbitmq.RabbitMQOutput#DEFAULT_EXCHANGE }
* Exchange to send messages to.
*
*
* {@value PROPERTY_routingKey }
* String (converted)
* false
* null
* The logging event level will be used by default.
*
*
* {@value PROPERTY_declareExchange }
* Boolean
* false
* null
* Declare exchange on start. Default is false.
*
*
* {@value PROPERTY_host }
* String
* false
* null
* Host.
*
*
* {@value PROPERTY_username }
* String
* false
* null
* Set user name if not null outside of URI.
*
*
* {@value PROPERTY_password }
* String
* false
* null
* Set password if not null outside of URI.
*
*
* {@value PROPERTY_port }
* Integer
* false
* null
* Set port if not null.
*
*
* {@value PROPERTY_appId }
* String
* false
* null
* Sets the message appId if not null.
*
*
* {@value PROPERTY_connectionName }
* String
* false
* null
* Connection name if not null.
*
*
* {@value PROPERTY_exchangeType }
* String
* false
* {@value io.jstach.rainbowgum.rabbitmq.RabbitMQOutput#DEFAULT_EXCHANGE_TYPE }
* Exchange type like "topic" covered in rabbitmq doc.
*
*
* {@value PROPERTY_virtualHost }
* String
* false
* null
* Sets virtualhost if not null.
*
*
*/
public final class RabbitMQOutputBuilder implements io.jstach.rainbowgum.LogBuilder {
/**
* The properties to be retrieved from config will have
* this prefix.
*/
static final String PROPERTY_PREFIX = "logging.output.{name}.";
/**
* {@value #PROPERTY_uri } = java.net.URI
Passed to the rabbitmq connection factory.
*/
static final String PROPERTY_uri = PROPERTY_PREFIX + "uri";
/**
* {@value #PROPERTY_exchange } = java.lang.String
Exchange to send messages to.
*/
static final String PROPERTY_exchange = PROPERTY_PREFIX + "exchange";
/**
* {@value #PROPERTY_routingKey } = java.util.function.Function
The logging event level will be used by default.
*/
static final String PROPERTY_routingKey = PROPERTY_PREFIX + "routingKey";
/**
* {@value #PROPERTY_declareExchange } = java.lang.Boolean
Declare exchange on start. Default is false.
*/
static final String PROPERTY_declareExchange = PROPERTY_PREFIX + "declareExchange";
/**
* {@value #PROPERTY_host } = java.lang.String
Host.
*/
static final String PROPERTY_host = PROPERTY_PREFIX + "host";
/**
* {@value #PROPERTY_username } = java.lang.String
Set user name if not null outside of URI.
*/
static final String PROPERTY_username = PROPERTY_PREFIX + "username";
/**
* {@value #PROPERTY_password } = java.lang.String
Set password if not null outside of URI.
*/
static final String PROPERTY_password = PROPERTY_PREFIX + "password";
/**
* {@value #PROPERTY_port } = java.lang.Integer
Set port if not null.
*/
static final String PROPERTY_port = PROPERTY_PREFIX + "port";
/**
* {@value #PROPERTY_appId } = java.lang.String
Sets the message appId if not null.
*/
static final String PROPERTY_appId = PROPERTY_PREFIX + "appId";
/**
* {@value #PROPERTY_connectionName } = java.lang.String
Connection name if not null.
*/
static final String PROPERTY_connectionName = PROPERTY_PREFIX + "connectionName";
/**
* {@value #PROPERTY_exchangeType } = java.lang.String
Exchange type like "topic" covered in rabbitmq doc.
*/
static final String PROPERTY_exchangeType = PROPERTY_PREFIX + "exchangeType";
/**
* {@value #PROPERTY_virtualHost } = java.lang.String
Sets virtualhost if not null.
*/
static final String PROPERTY_virtualHost = PROPERTY_PREFIX + "virtualHost";
private final String propertyPrefix;
final Property property_uri;
final Property property_exchange;
final Property> property_routingKey;
final Property property_declareExchange;
final Property property_host;
final Property property_username;
final Property property_password;
final Property property_port;
final Property property_appId;
final Property property_connectionName;
final Property property_exchangeType;
final Property property_virtualHost;
private final java.lang.String name;
private [email protected] URI uri = null;
private java.lang.String exchange = io.jstach.rainbowgum.rabbitmq.RabbitMQOutput.DEFAULT_EXCHANGE;
private [email protected] Function routingKey = null;
private [email protected] Boolean declareExchange = null;
private [email protected] String host = null;
private [email protected] String username = null;
private [email protected] String password = null;
private [email protected] Integer port = null;
private [email protected] String appId = null;
private [email protected] String connectionName = null;
private [email protected] String exchangeType = io.jstach.rainbowgum.rabbitmq.RabbitMQOutput.DEFAULT_EXCHANGE_TYPE;
private [email protected] String virtualHost = null;
/**
* Create a builder for {@code io.jstach.rainbowgum.rabbitmq.RabbitMQOutput }.
* @param name will fill {name}
in logging.output.{name}.
. Used to resolve config and give the output a name.
*/
public RabbitMQOutputBuilder(
java.lang.String name
) {
java.util.Map prefixParameters = java.util.Map.of(
"name", name
);
this.propertyPrefix = LogProperties.interpolateKey(PROPERTY_PREFIX, prefixParameters);
this.name = name;
property_uri = Property.builder()
.ofURI()
.build(LogProperties.interpolateKey(PROPERTY_uri, prefixParameters));
property_exchange = Property.builder()
.build(LogProperties.interpolateKey(PROPERTY_exchange, prefixParameters));
property_routingKey = Property.builder()
.map(_v -> io.jstach.rainbowgum.rabbitmq.RabbitMQOutput.toRoutingKeyFunction(_v))
.build(LogProperties.interpolateKey(PROPERTY_routingKey, prefixParameters));
property_declareExchange = Property.builder()
.ofBoolean()
.build(LogProperties.interpolateKey(PROPERTY_declareExchange, prefixParameters));
property_host = Property.builder()
.build(LogProperties.interpolateKey(PROPERTY_host, prefixParameters));
property_username = Property.builder()
.build(LogProperties.interpolateKey(PROPERTY_username, prefixParameters));
property_password = Property.builder()
.build(LogProperties.interpolateKey(PROPERTY_password, prefixParameters));
property_port = Property.builder()
.ofInt()
.build(LogProperties.interpolateKey(PROPERTY_port, prefixParameters));
property_appId = Property.builder()
.build(LogProperties.interpolateKey(PROPERTY_appId, prefixParameters));
property_connectionName = Property.builder()
.build(LogProperties.interpolateKey(PROPERTY_connectionName, prefixParameters));
property_exchangeType = Property.builder()
.build(LogProperties.interpolateKey(PROPERTY_exchangeType, prefixParameters));
property_virtualHost = Property.builder()
.build(LogProperties.interpolateKey(PROPERTY_virtualHost, prefixParameters));
}
/**
* Sets uri.
* Passed to the rabbitmq connection factory.
* Default is null
.
* @param uri {@value #PROPERTY_uri } = java.net.URI
Passed to the rabbitmq connection factory.
* @return this builder.
*/
public RabbitMQOutputBuilder uri([email protected] URI uri) {
this.uri = uri;
return this;
}
/**
* Sets required exchange.
* Exchange to send messages to.
* Default is {@value io.jstach.rainbowgum.rabbitmq.RabbitMQOutput#DEFAULT_EXCHANGE }.
* @param exchange {@value #PROPERTY_exchange } = java.lang.String
Exchange to send messages to.
* @return this builder.
*/
public RabbitMQOutputBuilder exchange(java.lang.String exchange) {
this.exchange = exchange;
return this;
}
/**
* Sets routingKey.
* The logging event level will be used by default.
* Default is null
.
* @param routingKey {@value #PROPERTY_routingKey } = java.util.function.Function
The logging event level will be used by default.
* @return this builder.
*/
public RabbitMQOutputBuilder routingKey([email protected] Function routingKey) {
this.routingKey = routingKey;
return this;
}
/**
* Sets declareExchange.
* Declare exchange on start. Default is false.
* Default is null
.
* @param declareExchange {@value #PROPERTY_declareExchange } = java.lang.Boolean
Declare exchange on start. Default is false.
* @return this builder.
*/
public RabbitMQOutputBuilder declareExchange([email protected] Boolean declareExchange) {
this.declareExchange = declareExchange;
return this;
}
/**
* Sets host.
* Host.
* Default is null
.
* @param host {@value #PROPERTY_host } = java.lang.String
Host.
* @return this builder.
*/
public RabbitMQOutputBuilder host([email protected] String host) {
this.host = host;
return this;
}
/**
* Sets username.
* Set user name if not null outside of URI.
* Default is null
.
* @param username {@value #PROPERTY_username } = java.lang.String
Set user name if not null outside of URI.
* @return this builder.
*/
public RabbitMQOutputBuilder username([email protected] String username) {
this.username = username;
return this;
}
/**
* Sets password.
* Set password if not null outside of URI.
* Default is null
.
* @param password {@value #PROPERTY_password } = java.lang.String
Set password if not null outside of URI.
* @return this builder.
*/
public RabbitMQOutputBuilder password([email protected] String password) {
this.password = password;
return this;
}
/**
* Sets port.
* Set port if not null.
* Default is null
.
* @param port {@value #PROPERTY_port } = java.lang.Integer
Set port if not null.
* @return this builder.
*/
public RabbitMQOutputBuilder port([email protected] Integer port) {
this.port = port;
return this;
}
/**
* Sets appId.
* Sets the message appId if not null.
* Default is null
.
* @param appId {@value #PROPERTY_appId } = java.lang.String
Sets the message appId if not null.
* @return this builder.
*/
public RabbitMQOutputBuilder appId([email protected] String appId) {
this.appId = appId;
return this;
}
/**
* Sets connectionName.
* Connection name if not null.
* Default is null
.
* @param connectionName {@value #PROPERTY_connectionName } = java.lang.String
Connection name if not null.
* @return this builder.
*/
public RabbitMQOutputBuilder connectionName([email protected] String connectionName) {
this.connectionName = connectionName;
return this;
}
/**
* Sets exchangeType.
* Exchange type like "topic" covered in rabbitmq doc.
* Default is {@value io.jstach.rainbowgum.rabbitmq.RabbitMQOutput#DEFAULT_EXCHANGE_TYPE }.
* @param exchangeType {@value #PROPERTY_exchangeType } = java.lang.String
Exchange type like "topic" covered in rabbitmq doc.
* @return this builder.
*/
public RabbitMQOutputBuilder exchangeType([email protected] String exchangeType) {
this.exchangeType = exchangeType;
return this;
}
/**
* Sets virtualHost.
* Sets virtualhost if not null.
* Default is null
.
* @param virtualHost {@value #PROPERTY_virtualHost } = java.lang.String
Sets virtualhost if not null.
* @return this builder.
*/
public RabbitMQOutputBuilder virtualHost([email protected] String virtualHost) {
this.virtualHost = virtualHost;
return this;
}
/**
* Creates {@code io.jstach.rainbowgum.rabbitmq.RabbitMQOutput } from this builder.
* @return {@code io.jstach.rainbowgum.rabbitmq.RabbitMQOutput }.
*/
public io.jstach.rainbowgum.rabbitmq.RabbitMQOutput build() {
return io.jstach.rainbowgum.rabbitmq.RabbitMQOutput.of(
this.name
, this.uri
, property_exchange.require(this.exchange)
, this.routingKey
, this.declareExchange
, this.host
, this.username
, this.password
, this.port
, this.appId
, this.connectionName
, this.exchangeType
, this.virtualHost
);
}
@Override
public RabbitMQOutputBuilder fromProperties(LogProperties properties) {
var __v = LogProperty.Validator.of(this.getClass());
var _uri = property_uri.get(properties).or(this.uri);
__v.addIfError(_uri);
var _exchange = property_exchange.get(properties).or(this.exchange);
__v.add(_exchange);
var _routingKey = property_routingKey.get(properties).or(this.routingKey);
__v.addIfError(_routingKey);
var _declareExchange = property_declareExchange.get(properties).or(this.declareExchange);
__v.addIfError(_declareExchange);
var _host = property_host.get(properties).or(this.host);
__v.addIfError(_host);
var _username = property_username.get(properties).or(this.username);
__v.addIfError(_username);
var _password = property_password.get(properties).or(this.password);
__v.addIfError(_password);
var _port = property_port.get(properties).or(this.port);
__v.addIfError(_port);
var _appId = property_appId.get(properties).or(this.appId);
__v.addIfError(_appId);
var _connectionName = property_connectionName.get(properties).or(this.connectionName);
__v.addIfError(_connectionName);
var _exchangeType = property_exchangeType.get(properties).or(this.exchangeType);
__v.addIfError(_exchangeType);
var _virtualHost = property_virtualHost.get(properties).or(this.virtualHost);
__v.addIfError(_virtualHost);
__v.validate();
this.uri = _uri.valueOrNull();
this.exchange = _exchange.value();
this.routingKey = _routingKey.valueOrNull();
this.declareExchange = _declareExchange.valueOrNull();
this.host = _host.valueOrNull();
this.username = _username.valueOrNull();
this.password = _password.valueOrNull();
this.port = _port.valueOrNull();
this.appId = _appId.valueOrNull();
this.connectionName = _connectionName.valueOrNull();
this.exchangeType = _exchangeType.valueOrNull();
this.virtualHost = _virtualHost.valueOrNull();
return this;
}
/**
* Turns the builder into java.util.Properties like Map skipping values that are null.
* @param consumer apply is called where first arg is key and second is value.
*/
public void toProperties(java.util.function.BiConsumer consumer) {
var _uri = this.uri;
if (_uri != null) {
consumer.accept(property_uri.key(), property_uri.propertyString(_uri));
}
var _exchange = this.exchange;
if (_exchange != null) {
consumer.accept(property_exchange.key(), property_exchange.propertyString(_exchange));
}
var _routingKey = this.routingKey;
if (_routingKey != null) {
consumer.accept(property_routingKey.key(), property_routingKey.propertyString(_routingKey));
}
var _declareExchange = this.declareExchange;
if (_declareExchange != null) {
consumer.accept(property_declareExchange.key(), property_declareExchange.propertyString(_declareExchange));
}
var _host = this.host;
if (_host != null) {
consumer.accept(property_host.key(), property_host.propertyString(_host));
}
var _username = this.username;
if (_username != null) {
consumer.accept(property_username.key(), property_username.propertyString(_username));
}
var _password = this.password;
if (_password != null) {
consumer.accept(property_password.key(), property_password.propertyString(_password));
}
var _port = this.port;
if (_port != null) {
consumer.accept(property_port.key(), property_port.propertyString(_port));
}
var _appId = this.appId;
if (_appId != null) {
consumer.accept(property_appId.key(), property_appId.propertyString(_appId));
}
var _connectionName = this.connectionName;
if (_connectionName != null) {
consumer.accept(property_connectionName.key(), property_connectionName.propertyString(_connectionName));
}
var _exchangeType = this.exchangeType;
if (_exchangeType != null) {
consumer.accept(property_exchangeType.key(), property_exchangeType.propertyString(_exchangeType));
}
var _virtualHost = this.virtualHost;
if (_virtualHost != null) {
consumer.accept(property_virtualHost.key(), property_virtualHost.propertyString(_virtualHost));
}
}
/**
* The interpolated property prefix: {@value #PROPERTY_PREFIX}.
* @return resolved prefix which should end with a ".
".
*/
@Override
public String propertyPrefix() {
return this.propertyPrefix;
}
}