本文整理汇总了Java中org.springframework.kafka.core.ProducerFactory类的典型用法代码示例。如果您正苦于以下问题:Java ProducerFactory类的具体用法?Java ProducerFactory怎么用?Java ProducerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProducerFactory类属于org.springframework.kafka.core包,在下文中一共展示了ProducerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ProducerConfigurationMessageHandler
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
ProducerConfigurationMessageHandler(KafkaTemplate<byte[], byte[]> kafkaTemplate, String topic,
ExtendedProducerProperties<KafkaProducerProperties> producerProperties,
ProducerFactory<byte[], byte[]> producerFactory) {
super(kafkaTemplate);
setTopicExpression(new LiteralExpression(topic));
setMessageKeyExpression(producerProperties.getExtension().getMessageKeyExpression());
setBeanFactory(KafkaMessageChannelBinder.this.getBeanFactory());
if (producerProperties.isPartitioned()) {
SpelExpressionParser parser = new SpelExpressionParser();
setPartitionIdExpression(parser.parseExpression("headers." + BinderHeaders.PARTITION_HEADER));
}
if (producerProperties.getExtension().isSync()) {
setSync(true);
}
this.producerFactory = producerFactory;
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:17,代码来源:KafkaMessageChannelBinder.java
示例2: setUp
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// set up the Kafka producer properties
Map<String, Object> senderProperties =
KafkaTestUtils.senderProps(AllSpringKafkaTests.embeddedKafka.getBrokersAsString());
// create a Kafka producer factory
ProducerFactory<String, String> producerFactory =
new DefaultKafkaProducerFactory<String, String>(senderProperties);
// create a Kafka template
template = new KafkaTemplate<>(producerFactory);
// set the default topic to send to
template.setDefaultTopic(AllSpringKafkaTests.RECEIVER_TOPIC);
// wait until the partitions are assigned
for (MessageListenerContainer messageListenerContainer : kafkaListenerEndpointRegistry
.getListenerContainers()) {
ContainerTestUtils.waitForAssignment(messageListenerContainer,
AllSpringKafkaTests.embeddedKafka.getPartitionsPerTopic());
}
}
示例3: setUp
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// set up the Kafka producer properties
Map<String, Object> senderProperties =
KafkaTestUtils.senderProps(embeddedKafka.getBrokersAsString());
// create a Kafka producer factory
ProducerFactory<String, String> producerFactory =
new DefaultKafkaProducerFactory<String, String>(senderProperties);
// create a Kafka template
template = new KafkaTemplate<>(producerFactory);
// set the default topic to send to
template.setDefaultTopic(RECEIVER_TOPIC);
// wait until the partitions are assigned
for (MessageListenerContainer messageListenerContainer : kafkaListenerEndpointRegistry
.getListenerContainers()) {
ContainerTestUtils.waitForAssignment(messageListenerContainer,
embeddedKafka.getPartitionsPerTopic());
}
}
示例4: producerFactory
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
/**
*
*
* @return producer instance(s)
*/
@SuppressWarnings("rawtypes")
@Bean
public ProducerFactory producerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfigs());
}
示例5: setup
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Before
public void setup() throws Exception {
Map<String, Object> consumerProps = KafkaTestUtils.consumerProps("testT", "false", embeddedKafka);
DefaultKafkaConsumerFactory<String, String> cf =
new DefaultKafkaConsumerFactory<>(consumerProps);
ContainerProperties containerProperties = new ContainerProperties(TEST_TOPIC);
container = new KafkaMessageListenerContainer<>(cf, containerProperties);
final BlockingQueue<ConsumerRecord<String, String>> records = new LinkedBlockingQueue<>();
container.setupMessageListener((MessageListener<String, String>) record -> {
log.error("Message received: " + record);
records.add(record);
});
container.start();
ContainerTestUtils.waitForAssignment(container, embeddedKafka.getPartitionsPerTopic());
Map<String, Object> senderProps = KafkaTestUtils.senderProps(embeddedKafka.getBrokersAsString());
ProducerFactory<String, String> pf =
new DefaultKafkaProducerFactory<>(senderProps);
template = new KafkaTemplate<>(pf);
template.setDefaultTopic(TEST_TOPIC);
}
示例6: producerFactory
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
public ProducerFactory<String, String> producerFactory() {
// set the producer properties
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, brokers);
properties.put(ProducerConfig.RETRIES_CONFIG, 0);
properties.put(ProducerConfig.BATCH_SIZE_CONFIG, 4096);
properties.put(ProducerConfig.LINGER_MS_CONFIG, 1);
properties.put(ProducerConfig.BUFFER_MEMORY_CONFIG, 40960);
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
return new DefaultKafkaProducerFactory<String, String>(properties);
}
示例7: start
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Override
public void start() {
if (null == this.keyStrategy) {
this.keyStrategy = new DefaultKeyStrategy();
}
this.addProducerConfigValue(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class);
this.addProducerConfigValue(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class);
ProducerFactory<byte[], byte[]> producerFactory = new DefaultKafkaProducerFactory<>(this.producerConfig);
this.kafkaTemplate = new KafkaTemplate<>(producerFactory);
this.kafkaTemplate.setDefaultTopic(this.topic.trim());
super.start();
}
示例8: createTemplate
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
private <T> KafkaTemplate<Integer, T> createTemplate(Object keySer, Object valSer) {
Map<String, Object> senderProps = senderProps(keySer, valSer);
ProducerFactory<Integer, T> pf =
new DefaultKafkaProducerFactory<>(senderProps);
KafkaTemplate<Integer, T> template = new KafkaTemplate<>(pf);
return template;
}
示例9: producerFactory
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Bean
public ProducerFactory<String, String> producerFactory() {
Map<String, Object> props = new HashMap<>();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, this.configProperties.getBrokerAddress());
props.put(ProducerConfig.RETRIES_CONFIG, 0);
props.put(ProducerConfig.BATCH_SIZE_CONFIG, 16384);
props.put(ProducerConfig.LINGER_MS_CONFIG, 1);
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, 33554432);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
return new DefaultKafkaProducerFactory<>(props);
}
示例10: producerFactory
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Bean
public ProducerFactory<String, Foo> producerFactory() {
Map<String, Object> props = new HashMap<>();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, this.configProperties.getBrokerAddress());
props.put(ProducerConfig.RETRIES_CONFIG, 0);
props.put(ProducerConfig.BATCH_SIZE_CONFIG, 16384);
props.put(ProducerConfig.LINGER_MS_CONFIG, 1);
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, 33554432);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
return new DefaultKafkaProducerFactory<>(props);
}
示例11: producerFactory
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Bean
public ProducerFactory<String, AvMessage> producerFactory() {
Map<String, Object> configProps = new HashMap<>();
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
return new DefaultKafkaProducerFactory<>(configProps);
}
示例12: fileServerProducerFactory
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Bean
public ProducerFactory<String, AvMessage> fileServerProducerFactory() {
Map<String, Object> configProps = new HashMap<>();
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
return new DefaultKafkaProducerFactory<>(configProps);
}
示例13: TracingProducerFactory
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
public TracingProducerFactory(ProducerFactory<K, V> producerFactory, Tracer tracer) {
this.producerFactory = producerFactory;
this.tracer = tracer;
}
示例14: producerFactory
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Bean
public ProducerFactory<Integer, String> producerFactory() {
return new TracingProducerFactory<>(new DefaultKafkaProducerFactory<>(
KafkaTestUtils.producerProps(embeddedKafka)), tracer());
}
示例15: producerFactory
import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Bean
public ProducerFactory<String, Event> producerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfigs());
}