generator.server.springboot.broker.pulsar.PulsarProperties.mustache Maven / Gradle / Ivy
package {{packageName}}.wire.pulsar.infrastructure.config;
import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
import org.apache.pulsar.client.impl.conf.ConsumerConfigurationData;
import org.apache.pulsar.client.impl.conf.ProducerConfigurationData;
import org.apache.pulsar.shade.com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.pulsar.shade.com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
@Configuration
@ConfigurationProperties(prefix = "pulsar")
public class PulsarProperties {
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private Map client = new HashMap<>();
private Map consumer = new HashMap<>();
private Map producer = new HashMap<>();
public Map getClientProps() {
return client;
}
public void setClient(ClientConfigurationData clientConfig) throws JsonProcessingException {
String json = OBJECT_MAPPER.writeValueAsString(clientConfig);
this.client = OBJECT_MAPPER.readerForMapOf(Object.class).readValue(json);
}
public Map getConsumerProps() {
return consumer;
}
public void setConsumer(ConsumerConfigurationData> consumerConfig) throws JsonProcessingException {
String json = OBJECT_MAPPER.writeValueAsString(consumerConfig);
this.consumer = OBJECT_MAPPER.readerForMapOf(Object.class).readValue(json);
}
public Map getProducerProps() {
return producer;
}
public void setProducer(ProducerConfigurationData producerConfig) throws JsonProcessingException {
String json = OBJECT_MAPPER.writeValueAsString(producerConfig);
this.producer = OBJECT_MAPPER.readerForMapOf(Object.class).readValue(json);
}
}