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


Java MessageAndMetadata.topic方法代码示例

本文整理汇总了Java中kafka.message.MessageAndMetadata.topic方法的典型用法代码示例。如果您正苦于以下问题:Java MessageAndMetadata.topic方法的具体用法?Java MessageAndMetadata.topic怎么用?Java MessageAndMetadata.topic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kafka.message.MessageAndMetadata的用法示例。


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

示例1: run

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
public void run() {
 	Iote2eRequestReuseItem iote2eRequestReuseItem = new Iote2eRequestReuseItem();
     ConsumerIterator<byte[], byte[]> it = kafkaStream.iterator();
     while (it.hasNext()) {
MessageAndMetadata<byte[], byte[]> messageAndMetadata = it.next();
String key = new String(messageAndMetadata.key());
try {
      	String summary = 
      			"Thread " + threadNumber + 
      			", topic=" + messageAndMetadata.topic() + 
      			", partition=" + messageAndMetadata.partition() + 
      			", key=" + key + 
      			", offset=" + messageAndMetadata.offset() + 
      			", timestamp=" + messageAndMetadata.timestamp() + 
      			", timestampType=" + messageAndMetadata.timestampType() + 
      			", iote2eRequest=" + iote2eRequestReuseItem.fromByteArray(messageAndMetadata.message()).toString();
      	logger.info(">>> Consumed: " + summary);
} catch( Exception e ) {
	logger.error(e.getMessage(), e);
}
     }
     logger.info(">>> Shutting down Thread: " + threadNumber);
 }
 
开发者ID:petezybrick,项目名称:iote2e,代码行数:24,代码来源:KafkaAvroDemo.java

示例2: run

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
public void run() {
    ConsumerIterator<byte[], byte[]> it = kafkaStream.iterator();
    while (it.hasNext()) {
    	MessageAndMetadata<byte[], byte[]> messageAndMetadata = it.next();
    	String key = new String(  messageAndMetadata.key() );
    	String message = new String(  messageAndMetadata.message() );
    	String summary = 
    			"Thread " + threadNumber + 
    			", topic=" + messageAndMetadata.topic() + 
    			", partition=" + messageAndMetadata.partition() + 
    			", key=" + key + 
    			", message=" + message + 
    			", offset=" + messageAndMetadata.offset() + 
    			", timestamp=" + messageAndMetadata.timestamp() + 
    			", timestampType=" + messageAndMetadata.timestampType();
    	logger.info(">>> Consumed: " + summary);
    }
    logger.info(">>> Shutting down Thread: " + threadNumber);
}
 
开发者ID:petezybrick,项目名称:iote2e,代码行数:20,代码来源:KafkaStringDemo.java

示例3: run

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
public void run() {
	try {
		ConsumerIterator<byte[], byte[]> it = m_stream.iterator();
		Injection<GenericRecord, byte[]> recordInjection = GenericAvroCodecs.toBinary(User.getClassSchema());

		while (it.hasNext()) {
			MessageAndMetadata<byte[], byte[]> messageAndMetadata = it.next();
			String key = new String(messageAndMetadata.key());
			User user = genericRecordToUser(recordInjection.invert(messageAndMetadata.message()).get());
			// User user = (User)
			// recordInjection.invert(messageAndMetadata.message()).get();
			String summary = "Thread " + m_threadNumber + ", topic=" + messageAndMetadata.topic() + ", partition="
					+ messageAndMetadata.partition() + ", key=" + key + ", user=" + user.toString() + ", offset="
					+ messageAndMetadata.offset() + ", timestamp=" + messageAndMetadata.timestamp()
					+ ", timestampType=" + messageAndMetadata.timestampType();
			System.out.println(summary);
		}
		System.out.println("Shutting down Thread: " + m_threadNumber);
	} catch (Exception e) {
		System.out.println("Exception in thread "+m_threadNumber);
		System.out.println(e);
		e.printStackTrace();
	}
}
 
开发者ID:petezybrick,项目名称:iote2e,代码行数:25,代码来源:AvroConsumerThread.java

示例4: run

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
public void run() {
    ConsumerIterator<byte[], byte[]> it = kafkaStream.iterator();
    while (it.hasNext()) {
    	MessageAndMetadata<byte[], byte[]> messageAndMetadata = it.next();
    	String key = new String(  messageAndMetadata.key() );
    	String message = new String(  messageAndMetadata.message() );
    	String summary = 
    			"Thread " + threadNumber + 
    			", topic=" + messageAndMetadata.topic() + 
    			", partition=" + messageAndMetadata.partition() + 
    			", key=" + key + 
    			", message=" + message + 
    			", offset=" + messageAndMetadata.offset() + 
    			", timestamp=" + messageAndMetadata.timestamp() + 
    			", timestampType=" + messageAndMetadata.timestampType();
    	System.out.println(summary);
    }
    System.out.println("Shutting down Thread: " + threadNumber);
}
 
开发者ID:petezybrick,项目名称:iote2e,代码行数:20,代码来源:ConsumerDemoThread.java

示例5: next

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
@Override
public MessageAndMetadata<byte[],byte[]> next() {
	readCount.incrementAndGet();
	lock.lock();
	try {
		while(queue.size()==0){
			notEmpty.await();
		}
		MessageAndMetadata<byte[], byte[]> t= queue.poll();//queue.take();
		notFull.signalAll();
		TopicAndPartition key = new TopicAndPartition(t.topic(), t.partition());
		PartitionReader reader=partitionMap.get(key);
		if(reader!=null)
		{
			commitCount.incrementAndGet();
			reader.getAndSetCommitOffset(t.offset());
			return t;
		}
	} catch (Exception e) {
		LOG.log("Read Message next() exception:",e);
	}finally{
		lock.unlock();
	}
	return null;
}
 
开发者ID:pulsarIO,项目名称:druid-kafka-ext,代码行数:26,代码来源:SimpleConsumerEx.java

示例6: run

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
@Override
public void run() {
	ConsumerIterator<String, String> i = records.iterator();
	while (i.hasNext()) {
		final MessageAndMetadata<String, String> mm = i.next();
		String topic = mm.topic();
		final Set<ConsumeCallback> cbs = callbacks.get(topic);
		if (cbs != null) {
			
							for (ConsumeCallback cb : cbs)
								try{
								cb.process(mm);
								}catch(Exception ex)
							{
									ex.printStackTrace();
							}
					
		}
	}
}
 
开发者ID:BaixiangLiu,项目名称:fudanweixin,代码行数:21,代码来源:CallbackThread.java

示例7: receive

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
@Override
public BaseConsumerRecord receive() {
  if (!_iter.hasNext())
    return null;
  MessageAndMetadata<String, String> record = _iter.next();
  return new BaseConsumerRecord(record.topic(), record.partition(), record.offset(), record.key(), record.message());
}
 
开发者ID:linkedin,项目名称:kafka-monitor,代码行数:8,代码来源:OldConsumer.java

示例8: run

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
public void run() {
	try {
		ConsumerIterator<byte[], byte[]> it = stream.iterator();
		BinaryDecoder binaryDecoder = null;
		Weather weatherRead = null;
		DatumReader<Weather> datumReaderWeather = new SpecificDatumReader<Weather>(Weather.getClassSchema());

		while (it.hasNext()) {
			MessageAndMetadata<byte[], byte[]> messageAndMetadata = it.next();
			String key = new String(messageAndMetadata.key());
			binaryDecoder = DecoderFactory.get().binaryDecoder(messageAndMetadata.message(), binaryDecoder);
			weatherRead = datumReaderWeather.read(weatherRead, binaryDecoder);
			// User user = (User)
			// recordInjection.invert(messageAndMetadata.message()).get();
			String summary = "Thread " + threadNumber + ", topic=" + messageAndMetadata.topic() + ", partition="
					+ messageAndMetadata.partition() + ", key=" + key + ", offset="
					+ messageAndMetadata.offset() + ", timestamp=" + messageAndMetadata.timestamp()
					+ ", timestampType=" + messageAndMetadata.timestampType()
					+ ", weatherRead=" + weatherRead.toString();
			System.out.println(summary);
		}
		System.out.println("Shutting down Thread: " + threadNumber);
	} catch (Exception e) {
		System.out.println("Exception in thread "+threadNumber);
		System.out.println(e);
		e.printStackTrace();
	}
}
 
开发者ID:petezybrick,项目名称:iote2e,代码行数:29,代码来源:AvroConsumerWeatherThread.java

示例9: run

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
public void run() {
	try {
		ConsumerIterator<byte[], byte[]> it = stream.iterator();
		BinaryDecoder binaryDecoder = null;
		Wave waveRead = null;
		DatumReader<Wave> datumReaderWave = new SpecificDatumReader<Wave>(Wave.getClassSchema());

		while (it.hasNext()) {
			MessageAndMetadata<byte[], byte[]> messageAndMetadata = it.next();
			String key = new String(messageAndMetadata.key());
			binaryDecoder = DecoderFactory.get().binaryDecoder(messageAndMetadata.message(), binaryDecoder);
			waveRead = datumReaderWave.read(waveRead, binaryDecoder);
			// User user = (User)
			// recordInjection.invert(messageAndMetadata.message()).get();
			String summary = ">>> CONSUMER: Thread " + threadNumber + ", topic=" + messageAndMetadata.topic() + ", partition="
					+ messageAndMetadata.partition() + ", key=" + key + ", offset="
					+ messageAndMetadata.offset() + ", timestamp=" + messageAndMetadata.timestamp()
					+ ", timestampType=" + messageAndMetadata.timestampType()
					+ ", waveRead=" + waveRead.toString();
			System.out.println(summary);
		}
		System.out.println("Shutting down Thread: " + threadNumber);
	} catch (Exception e) {
		System.out.println("Exception in thread "+threadNumber);
		System.out.println(e);
		e.printStackTrace();
	}
}
 
开发者ID:petezybrick,项目名称:iote2e,代码行数:29,代码来源:AvroConsumerWaveThread.java

示例10: run

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void run() {
  for (MessageAndMetadata<byte[], byte[]> messageAndMetadata : (Iterable<MessageAndMetadata<byte[], byte[]>>) stream) {
    String topic = messageAndMetadata.topic();
    byte[] key = messageAndMetadata.key();
    byte[] message = messageAndMetadata.message();
    sendText(topic, key, message);
  }
}
 
开发者ID:nikore,项目名称:kafka-ws,代码行数:11,代码来源:KafkaConsumer.java

示例11: run

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
public void run() {
    ConsumerIterator<String, String> iter = stream.iterator();
    while (iter.hasNext()) {
        MessageAndMetadata<String, String> msg = iter.next();
        Envelope message = new Envelope(msg.key(), msg.message(), msg.topic());
        task.process(message, producer);
    }
}
 
开发者ID:Team-Whitespace,项目名称:BASK,代码行数:9,代码来源:TaskThread.java

示例12: Message

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
public Message(MessageAndMetadata<byte[], byte[]> message) {
    this.topic = message.topic();

    this.key = message.key() != null ? new String(message.key(), Charset.forName("utf-8")) : null;
    this.message = new String(message.message(), Charset.forName("utf-8"));

    this.partition = message.partition();
    this.offset = message.offset();
}
 
开发者ID:elodina,项目名称:dropwizard-kafka-http,代码行数:10,代码来源:MessageResource.java

示例13: nextMetaMessage

import kafka.message.MessageAndMetadata; //导入方法依赖的package包/类
public IngestionMetaMessage nextMetaMessage() {
 MessageAndMetadata<Long, String> meta = it.next();
 return new IngestionMetaMessage(meta.key(), meta.message(), meta.topic(), meta.partition(), meta.offset());
}
 
开发者ID:IntersysConsulting,项目名称:ingestive,代码行数:5,代码来源:IngestionHighLevelConsumer.java


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