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


Java Decoder类代码示例

本文整理汇总了Java中kafka.serializer.Decoder的典型用法代码示例。如果您正苦于以下问题:Java Decoder类的具体用法?Java Decoder怎么用?Java Decoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Decoder类属于kafka.serializer包,在下文中一共展示了Decoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Unbound

import kafka.serializer.Decoder; //导入依赖的package包/类
Unbound(Class<? extends Decoder<K>> keyDecoder,
        Class<? extends Decoder<V>> valueDecoder, Class<K> key,
        Class<V> value, Set<String> topics, Map<String, String> kafkaParams) {
  checkNotNull(keyDecoder, "need to set the key decoder class of a KafkaIO.Read transform");
  checkNotNull(
      valueDecoder, "need to set the value decoder class of a KafkaIO.Read transform");
  checkNotNull(key, "need to set the key class of a KafkaIO.Read transform");
  checkNotNull(value, "need to set the value class of a KafkaIO.Read transform");
  checkNotNull(topics, "need to set the topics of a KafkaIO.Read transform");
  checkNotNull(kafkaParams, "need to set the kafkaParams of a KafkaIO.Read transform");
  this.keyDecoderClass = keyDecoder;
  this.valueDecoderClass = valueDecoder;
  this.keyClass = key;
  this.valueClass = value;
  this.topics = topics;
  this.kafkaParams = kafkaParams;
}
 
开发者ID:FreshetDMS,项目名称:Freshet-Deprecated,代码行数:18,代码来源:KafkaIO.java

示例2: KafkaConsumerPool

import kafka.serializer.Decoder; //导入依赖的package包/类
KafkaConsumerPool(final int maxSize, final int expireAfterMins, final String brokers, final Decoder<K> keyMapper, final Decoder<V> valueMapper) {
    this.maxSize = maxSize;
    this.expireAfterMins = expireAfterMins;
    this.brokerList = KafkaMetaData.createBrokerList(brokers);
    this.keyMapper = keyMapper;
    this.valueMapper = valueMapper;
    this.pool = createPool();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                LOG.info("Shutdown Hook: Shutting down KafkaConsumerPool");
                shutdown();
            } catch (Exception e) {
                LOG.error(e.getMessage(), e);
            }
        }
    });
}
 
开发者ID:jeoffreylim,项目名称:maelstrom,代码行数:21,代码来源:KafkaConsumerPool.java

示例3: run

import kafka.serializer.Decoder; //导入依赖的package包/类
public void run(Decoder<K> keyDecoder, Decoder<V> valueDecoder){
	Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
       topicCountMap.put(topic, threadNum);
       Map<String, List<KafkaStream<K, V>>> consumerMap = consumer.createMessageStreams(topicCountMap, keyDecoder, valueDecoder);
       
       List<KafkaStream<K, V>> streams = consumerMap.get(topic);
       
       executor = Executors.newFixedThreadPool(threadNum);
    
       int threadNo = 0;
	for (final KafkaStream<K, V> stream : streams) {
       	ConsumerWorker<K, V> worker = new ConsumerWorker<K, V>(stream, threadNo);
       	executor.submit(worker);
       	threadNo++;
       }
}
 
开发者ID:sn3009,项目名称:EasyMessage,代码行数:17,代码来源:ConsumerEngine.java

示例4: kafka

import kafka.serializer.Decoder; //导入依赖的package包/类
private static <K, V> TransformEvaluator<KafkaIO.Read.Unbound<K, V>> kafka() {
  return new TransformEvaluator<KafkaIO.Read.Unbound<K, V>>() {
    @Override
    public void evaluate(KafkaIO.Read.Unbound<K, V> transform, EvaluationContext context) {
      StreamingEvaluationContext sec = (StreamingEvaluationContext) context;
      JavaStreamingContext jssc = sec.getStreamingContext();
      Class<K> keyClazz = transform.getKeyClass();
      Class<V> valueClazz = transform.getValueClass();
      Class<? extends Decoder<K>> keyDecoderClazz = transform.getKeyDecoderClass();
      Class<? extends Decoder<V>> valueDecoderClazz = transform.getValueDecoderClass();
      Map<String, String> kafkaParams = transform.getKafkaParams();
      Set<String> topics = transform.getTopics();
      JavaPairInputDStream<K, V> inputPairStream = KafkaUtils.createDirectStream(jssc, keyClazz,
              valueClazz, keyDecoderClazz, valueDecoderClazz, kafkaParams, topics);
      JavaDStream<WindowedValue<KV<K, V>>> inputStream =
          inputPairStream.map(new Function<Tuple2<K, V>, KV<K, V>>() {
        @Override
        public KV<K, V> call(Tuple2<K, V> t2) throws Exception {
          return KV.of(t2._1(), t2._2());
        }
      }).map(WindowingHelpers.<KV<K, V>>windowFunction());
      sec.setStream(transform, inputStream);
    }
  };
}
 
开发者ID:shakamunyi,项目名称:spark-dataflow,代码行数:26,代码来源:StreamingTransformTranslator.java

示例5: Unbound

import kafka.serializer.Decoder; //导入依赖的package包/类
Unbound(Class<? extends Decoder<K>> keyDecoder,
        Class<? extends Decoder<V>> valueDecoder, Class<K> key,
        Class<V> value, Set<String> topics, Map<String, String> kafkaParams) {
  Preconditions.checkNotNull(keyDecoder,
      "need to set the key decoder class of a KafkaIO.Read transform");
  Preconditions.checkNotNull(valueDecoder,
      "need to set the value decoder class of a KafkaIO.Read transform");
  Preconditions.checkNotNull(key,
      "need to set the key class of aKafkaIO.Read transform");
  Preconditions.checkNotNull(value,
      "need to set the value class of a KafkaIO.Read transform");
  Preconditions.checkNotNull(topics,
      "need to set the topics of a KafkaIO.Read transform");
  Preconditions.checkNotNull(kafkaParams,
      "need to set the kafkaParams of a KafkaIO.Read transform");
  this.keyDecoderClass = keyDecoder;
  this.valueDecoderClass = valueDecoder;
  this.keyClass = key;
  this.valueClass = value;
  this.topics = topics;
  this.kafkaParams = kafkaParams;
}
 
开发者ID:shakamunyi,项目名称:spark-dataflow,代码行数:23,代码来源:KafkaIO.java

示例6: setup

import kafka.serializer.Decoder; //导入依赖的package包/类
private void setup(String groupId) {

	consumer = kafka.consumer.Consumer.createJavaConsumerConnector(
	            createConsumerConfig(groupId));
  
    // Request a single connection that gathers messages from all partitions 
	Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
    topicCountMap.put(topic, new Integer(1));
    
    // Construct the encoders/decoders for the message key and values
    Decoder<Long> keyDecoder = new LongSupport(new VerifiableProperties());
    Decoder<String> messageDecoder = new StringSupport(new VerifiableProperties());

	// Configure and request the desired streams using the topic map, encoder and decoder
    Map<String, List<KafkaStream<Long, String>>> consumerMap = consumer.createMessageStreams(topicCountMap, keyDecoder, messageDecoder);

	// We only get back one stream
    KafkaStream<Long, String> stream =  consumerMap.get(topic).get(0);
    
    // Capture the stream's iterator
    it = stream.iterator();
  }
 
开发者ID:IntersysConsulting,项目名称:ingestive,代码行数:23,代码来源:IngestionHighLevelConsumer.java

示例7: createStreams_withoutTopicFilterRegex_isOk

import kafka.serializer.Decoder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void createStreams_withoutTopicFilterRegex_isOk() {
    // Given
    final ConsumerFactory consumerFactory = new ConsumerFactory(createDefaultConsumerConfig());
    final ConsumerConnector consumer = mock(ConsumerConnector.class);
    when(consumer.createMessageStreamsByFilter(any(TopicFilter.class), anyInt(), any(Decoder.class), any(Decoder.class))).thenReturn(new ArraySeq(0));

    // When
    consumerFactory.createStreams(1, consumer);

    // Then
    verify(consumer).createMessageStreamsByFilter(
            refEq(new Whitelist(".*")), anyInt(), any(Decoder.class), any(Decoder.class)
    );
}
 
开发者ID:viadeo,项目名称:axon-kafka-terminal,代码行数:17,代码来源:ConsumerFactoryUTest.java

示例8: createStreams_withTopicFilterRegex_isOk

import kafka.serializer.Decoder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void createStreams_withTopicFilterRegex_isOk() {
    // Given
    final String rawRegex = "foo.*";
    final ConsumerConfig consumerConfig = createDefaultConsumerConfig();
    consumerConfig.props().props().setProperty(ConsumerFactory.CONSUMER_TOPIC_FILTER_REGEX, rawRegex);

    final ConsumerFactory consumerFactory = new ConsumerFactory(consumerConfig);
    final ConsumerConnector consumer = mock(ConsumerConnector.class);
    when(consumer.createMessageStreamsByFilter(any(TopicFilter.class), anyInt(), any(Decoder.class), any(Decoder.class))).thenReturn(new ArraySeq(0));

    // When
    consumerFactory.createStreams(1, consumer);

    // Then
    verify(consumer).createMessageStreamsByFilter(
            refEq(new Whitelist(rawRegex)), anyInt(), any(Decoder.class), any(Decoder.class)
    );
}
 
开发者ID:viadeo,项目名称:axon-kafka-terminal,代码行数:21,代码来源:ConsumerFactoryUTest.java

示例9: KafkaConsumerService

import kafka.serializer.Decoder; //导入依赖的package包/类
KafkaConsumerService(MetricRegistry metrics,
                     ConsumerConfig consumerConfig,
                     Map<String, Integer> topics,
                     Decoder<K> keyDecoder,
                     Decoder<V> valueDecoder,
                     MessageHandler<K, V> messageHandler) {

    MDC.put("group_id", consumerConfig.groupId());

    this.metrics = metrics;
    this.consumerConfig = consumerConfig;
    this.topics = topics;
    this.keyDecoder = keyDecoder;
    this.valueDecoder = valueDecoder;
    this.messageHandler = messageHandler;
}
 
开发者ID:addthis,项目名称:basis,代码行数:17,代码来源:KafkaConsumerService.java

示例10: createKeyDecoder

import kafka.serializer.Decoder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public final Decoder<K> createKeyDecoder() {
    try {
        return (Decoder<K>)keyMapper.getDeclaredConstructor(VerifiableProperties.class).newInstance(verifiableProperties != null ? new VerifiableProperties(verifiableProperties) : null);
    } catch (Exception e) {
        throw new IllegalArgumentException("Unable to create key decoder: " + e.getMessage(), e);
    }
}
 
开发者ID:jeoffreylim,项目名称:maelstrom,代码行数:9,代码来源:KafkaConsumerPoolFactory.java

示例11: createValueDecoder

import kafka.serializer.Decoder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public final Decoder<V> createValueDecoder() {
    try {
        return (Decoder<V>)valueMapper.getDeclaredConstructor(VerifiableProperties.class).newInstance(verifiableProperties != null ? new VerifiableProperties(verifiableProperties) : null);
    } catch (Exception e) {
        throw new IllegalArgumentException("Unable to create value decoder: " + e.getMessage(), e);
    }
}
 
开发者ID:jeoffreylim,项目名称:maelstrom,代码行数:9,代码来源:KafkaConsumerPoolFactory.java

示例12: KafkaConsumerFactory

import kafka.serializer.Decoder; //导入依赖的package包/类
KafkaConsumerFactory(final List<Broker> brokerList,
                     final Decoder<K> keyMapper,
                     final Decoder<V> valueMapper,
                     final String topic,
                     final Integer partition) {
    this.brokerList = brokerList;
    this.keyMapper = keyMapper;
    this.valueMapper = valueMapper;
    this.topic = topic;
    this.partition = partition;
}
 
开发者ID:jeoffreylim,项目名称:maelstrom,代码行数:12,代码来源:KafkaConsumerPool.java

示例13: KafkaConsumer

import kafka.serializer.Decoder; //导入依赖的package包/类
public KafkaConsumer(final List<Broker> brokerList, final String consumerGroup,
                     final Decoder<K> keyDecoder, final Decoder<V> valueDecoder,
                     final String topic, final int partitionId) {
    this.brokersList = brokerList;
    this.consumerGroup = consumerGroup;
    this.keyDecoder = keyDecoder;
    this.valueDecoder = valueDecoder;
    this.topic = topic;
    this.partitionId = partitionId;

    this.clientId = KafkaMetaData.createClientId(consumerGroup, topic, partitionId);
    this.leaderBrokerChecker = new LeaderBrokerChecker(brokersList, topic, partitionId);

    connect();
}
 
开发者ID:jeoffreylim,项目名称:maelstrom,代码行数:16,代码来源:KafkaConsumer.java

示例14: KafkaConsumer

import kafka.serializer.Decoder; //导入依赖的package包/类
public KafkaConsumer(final String topic, final String zkConnect, final String groupId, Decoder<Val> decoder){
	
	 
	 consumer = kafka.consumer.Consumer.createJavaConsumerConnector(
				new ConsumerConfig(getConsumerConfig(zkConnect, groupId)));
	 
	 Map<String, Integer> topicCountMap = new HashMap(){{
            put(topic, new Integer(1));
	 }};
	 Map<String, List<KafkaStream<byte[], Val>>> consumerMap = consumer.createMessageStreams(topicCountMap, new DefaultDecoder(null), decoder);
	 stream = consumerMap.get(topic).get(0);
}
 
开发者ID:rogers,项目名称:change-data-capture,代码行数:13,代码来源:KafkaConsumer.java

示例15: KafkaGenericAvroMutationDecoder

import kafka.serializer.Decoder; //导入依赖的package包/类
/**
 * Constructor used for testing.
 */
public KafkaGenericAvroMutationDecoder(Decoder<byte[]> _firstDeserializer) {
    //TODO: Move to AbstractAvroDeserilaizer
    if (_firstDeserializer == null) {
        firstDeserializer = new DefaultDecoder(null);
        //TODO: Should get this from config - look at KafkaProducer code...(in Kafka src)
    } else {
        firstDeserializer = _firstDeserializer;
    }

}
 
开发者ID:rogers,项目名称:change-data-capture,代码行数:14,代码来源:KafkaGenericAvroMutationDecoder.java


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