当前位置: 首页>>代码示例>>Java>>正文


Java ProducerFactory类代码示例

本文整理汇总了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());
  }
}
 
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:23,代码来源:SpringKafkaReceiverTest.java

示例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());
  }
}
 
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:23,代码来源:SpringKafkaReceiverTest.java

示例4: producerFactory

import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
/**
 * 
 * 
 * @return producer instance(s)
 */

@SuppressWarnings("rawtypes")
@Bean
public ProducerFactory producerFactory() {
	return new DefaultKafkaProducerFactory<>(producerConfigs());
}
 
开发者ID:sarojrout,项目名称:spring-tutorial,代码行数:12,代码来源:StudentProducerConfig.java

示例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);
}
 
开发者ID:underscorenico,项目名称:skeleton-oms-java,代码行数:21,代码来源:HelloProcessTest.java

示例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);
    }
 
开发者ID:cwenao,项目名称:springboot_cwenao,代码行数:15,代码来源:KafkaProducersConfig.java

示例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();
}
 
开发者ID:ilifan,项目名称:smart-framework,代码行数:13,代码来源:KafkaAppender.java

示例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;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:8,代码来源:SimpleKafkaIT.java

示例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);
}
 
开发者ID:SpringOnePlatform2016,项目名称:grussell-spring-kafka,代码行数:13,代码来源:CommonConfiguration.java

示例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);
}
 
开发者ID:SpringOnePlatform2016,项目名称:grussell-spring-kafka,代码行数:13,代码来源:JsonConfiguration.java

示例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);
}
 
开发者ID:dvoraka,项目名称:av-service,代码行数:10,代码来源:KafkaFileClientConfig.java

示例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);
}
 
开发者ID:dvoraka,项目名称:av-service,代码行数:10,代码来源:KafkaServerConfig.java

示例13: TracingProducerFactory

import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
public TracingProducerFactory(ProducerFactory<K, V> producerFactory, Tracer tracer) {
  this.producerFactory = producerFactory;
  this.tracer = tracer;
}
 
开发者ID:opentracing-contrib,项目名称:java-kafka-client,代码行数:5,代码来源:TracingProducerFactory.java

示例14: producerFactory

import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Bean
public ProducerFactory<Integer, String> producerFactory() {
  return new TracingProducerFactory<>(new DefaultKafkaProducerFactory<>(
      KafkaTestUtils.producerProps(embeddedKafka)), tracer());
}
 
开发者ID:opentracing-contrib,项目名称:java-kafka-client,代码行数:6,代码来源:TestConfiguration.java

示例15: producerFactory

import org.springframework.kafka.core.ProducerFactory; //导入依赖的package包/类
@Bean
public ProducerFactory<String, Event> producerFactory() {
	return new DefaultKafkaProducerFactory<>(producerConfigs());
}
 
开发者ID:italia,项目名称:daf-replicate-ingestion,代码行数:5,代码来源:SenderConfig.java


注:本文中的org.springframework.kafka.core.ProducerFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。