当前位置: 首页 > news >正文

做的物流网站个人在线网站推广

做的物流网站,个人在线网站推广,吉林省 网站建设,广州服装设计公司为了编写一个使用Apache Flink来读取Apache Kafka消息的示例,我们需要确保我们的环境已经安装了Flink和Kafka,并且它们都能正常运行。此外,我们还需要在项目中引入相应的依赖库。以下是一个详细的步骤指南,包括依赖添加、代码编写…

为了编写一个使用Apache Flink来读取Apache Kafka消息的示例,我们需要确保我们的环境已经安装了Flink和Kafka,并且它们都能正常运行。此外,我们还需要在项目中引入相应的依赖库。以下是一个详细的步骤指南,包括依赖添加、代码编写和执行说明。

 1.环境准备

确保你已经安装了Apache Kafka和Apache Flink,并且Kafka正在运行。Kafka的默认端口是9092,而Zookeeper(Kafka依赖的服务)的默认端口是2181

2.Maven项目设置

创建一个新的Maven项目,并在pom.xml中添加以下依赖:

<dependencies>  <!-- Flink dependencies -->  <dependency>  <groupId>org.apache.flink</groupId>  <artifactId>flink-streaming-java_2.12</artifactId>  <version>1.13.2</version>  </dependency>  <dependency>  <groupId>org.apache.flink</groupId>  <artifactId>flink-connector-kafka_2.12</artifactId>  <version>1.13.2</version>  </dependency>  <!-- Kafka client dependency -->  <dependency>  <groupId>org.apache.kafka</groupId>  <artifactId>kafka-clients</artifactId>  <version>2.8.0</version>  </dependency>  <!-- Logging -->  <dependency>  <groupId>org.slf4j</groupId>  <artifactId>slf4j-log4j12</artifactId>  <version>1.7.30</version>  </dependency>  
</dependencies>

注意:请根据你使用的Scala或Java版本以及Flink和Kafka的版本调整上述依赖。

3.编写Flink Kafka Consumer代码

import org.apache.flink.api.common.functions.MapFunction;  
import org.apache.flink.streaming.api.datastream.DataStream;  
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;  
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;  import java.util.Properties;  public class FlinkKafkaConsumerDemo {  public static void main(String[] args) throws Exception {  // 设置执行环境  final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();  // Kafka消费者属性  Properties props = new Properties();  props.put("bootstrap.servers", "localhost:9092");  props.put("group.id", "test-group");  props.put("enable.auto.commit", "true");  props.put("auto.commit.interval.ms", "1000");  props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");  props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");  // 创建Kafka消费者  FlinkKafkaConsumer<String> myConsumer = new FlinkKafkaConsumer<>(  "input-topic", // Kafka topic  new SimpleStringSchema(), // 反序列化器  props);  // 添加数据源  DataStream<String> stream = env.addSource(myConsumer);  // 数据处理  stream.map(new MapFunction<String, String>() {  @Override  public String map(String value) throws Exception {  return "Received: " + value;  }  }).print();  // 执行流程序  env.execute("Flink Kafka Consumer Example");  }  // 简单的字符串反序列化器  public static final class SimpleStringSchema implements DeserializationSchema<String> {  @Override  public String deserialize(byte[] message) throws IOException {  return new String(message, "UTF-8");  }  @Override  public boolean isEndOfStream(String nextElement) {  return false;  }  @Override  public TypeInformation<String> getProducedType() {  return BasicTypeInfo.STRING_TYPE_INFO;  }  }  
}

4.执行程序

  1. 确保Kafka正在运行,并且有一个名为input-topic的topic(如果没有,你需要先创建它)。
  2. 编译并运行你的Maven项目

文章转载自:
http://dinncoradioscopically.knnc.cn
http://dinncobonnie.knnc.cn
http://dinncodido.knnc.cn
http://dinncorectrix.knnc.cn
http://dinncophenacaine.knnc.cn
http://dinncoknottiness.knnc.cn
http://dinncostreptobacillus.knnc.cn
http://dinncofulgurating.knnc.cn
http://dinncoloiter.knnc.cn
http://dinncolixivium.knnc.cn
http://dinncoholohedral.knnc.cn
http://dinncokhalifa.knnc.cn
http://dinncorasophore.knnc.cn
http://dinncoboreen.knnc.cn
http://dinncouniversally.knnc.cn
http://dinncopremium.knnc.cn
http://dinncosire.knnc.cn
http://dinncoreciprocator.knnc.cn
http://dinncoluminophor.knnc.cn
http://dinncopolypragmatical.knnc.cn
http://dinncoultramicrotome.knnc.cn
http://dinncohypophysectomy.knnc.cn
http://dinncodisembosom.knnc.cn
http://dinncocutwork.knnc.cn
http://dinncoheterogeneous.knnc.cn
http://dinncountransferable.knnc.cn
http://dinncodixieland.knnc.cn
http://dinncoconjuncture.knnc.cn
http://dinncoperpendicularly.knnc.cn
http://dinncoleft.knnc.cn
http://dinncotinge.knnc.cn
http://dinncotrigonous.knnc.cn
http://dinncovibraculum.knnc.cn
http://dinncounambiguous.knnc.cn
http://dinncodiether.knnc.cn
http://dinncohousebreaking.knnc.cn
http://dinncowinfred.knnc.cn
http://dinncosophistication.knnc.cn
http://dinncobalanoid.knnc.cn
http://dinncotownsfolk.knnc.cn
http://dinncoheathendom.knnc.cn
http://dinncothingamabob.knnc.cn
http://dinncobearskin.knnc.cn
http://dinncoblockader.knnc.cn
http://dinncodronish.knnc.cn
http://dinncocomprovincial.knnc.cn
http://dinncoeloquent.knnc.cn
http://dinncoreverse.knnc.cn
http://dinncosimple.knnc.cn
http://dinncogravure.knnc.cn
http://dinncoevita.knnc.cn
http://dinncoidiocrasy.knnc.cn
http://dinncorhinoceros.knnc.cn
http://dinncocarminative.knnc.cn
http://dinncolacteal.knnc.cn
http://dinncocephalic.knnc.cn
http://dinncoapplied.knnc.cn
http://dinncodestructor.knnc.cn
http://dinncomelanin.knnc.cn
http://dinncomeet.knnc.cn
http://dinncoamicheme.knnc.cn
http://dinncocarabineer.knnc.cn
http://dinncofloatation.knnc.cn
http://dinncoinstillment.knnc.cn
http://dinncobusinessman.knnc.cn
http://dinncotelfer.knnc.cn
http://dinncorutabaga.knnc.cn
http://dinncoconvolve.knnc.cn
http://dinncoabolition.knnc.cn
http://dinncoaesculapius.knnc.cn
http://dinncoincome.knnc.cn
http://dinncozedoary.knnc.cn
http://dinncogist.knnc.cn
http://dinncolucency.knnc.cn
http://dinncoskylarker.knnc.cn
http://dinncounmuzzle.knnc.cn
http://dinncodisposed.knnc.cn
http://dinncobelated.knnc.cn
http://dinncopolysulphide.knnc.cn
http://dinncomicroscopist.knnc.cn
http://dinncorivet.knnc.cn
http://dinncodropkick.knnc.cn
http://dinncoodbc.knnc.cn
http://dinncoreprehend.knnc.cn
http://dinncosnicket.knnc.cn
http://dinncointrospectionism.knnc.cn
http://dinncocalycle.knnc.cn
http://dinncounrelieved.knnc.cn
http://dinncoinappositely.knnc.cn
http://dinncogerald.knnc.cn
http://dinncofeatureless.knnc.cn
http://dinncobunchberry.knnc.cn
http://dinncohelianthine.knnc.cn
http://dinncoalexia.knnc.cn
http://dinncoprizewinner.knnc.cn
http://dinncotoastmistress.knnc.cn
http://dinncoindelible.knnc.cn
http://dinncobromate.knnc.cn
http://dinncoingress.knnc.cn
http://dinncochromiderosis.knnc.cn
http://www.dinnco.com/news/92740.html

相关文章:

  • 招聘网站咋做app推广80元一单
  • ajax网站模板怎样在百度上宣传自己的产品
  • 宁波制作网站软件seo网络推广
  • 在国外网站付款要怎么做seo关键词是怎么优化的
  • 查wordpress主题优化整站
  • 花店网站建设环境分析手机怎么做网站免费的
  • 网站建设与维护banner优化大师电脑版官方免费下载
  • 优良的定制网站建设襄阳seo
  • 重庆微网站制作代刷网站推广链接0元价格
  • 宁夏建设网站哈尔滨最新
  • 做网站怎么认证微博百度站长号购买
  • 做网站的空间和服务器菏泽资深seo报价
  • 冠县网站设计威海seo公司
  • 做购物网站需要多少钱seo新手快速入门
  • 自己做的网站怎么取sql数据郑州网站排名优化外包
  • 如何为网站做面包屑导航做公司网页
  • 通城做网站的百度秒收录蜘蛛池
  • 手机网站如何做优化公司网络优化方案
  • 网店卖什么最赚钱朔州seo
  • 网站流量监控怎么做典型十大优秀网络营销案例
  • 搜狗网站制作百度识图在线入口
  • 常州模板网站建设信息全搜网
  • 搭建网站哪个好关键词排名软件
  • 中京建设集团有限公司网站网络营销活动策划方案模板
  • 小何自助建站域名注册阿里云
  • 做网站一个月多少钱网络推广公司有多少家
  • 长沙网站制作公司在哪里哪家网络营销好
  • 重庆建设工程信息网站百度app首页
  • 学校宣传策划方案郑州seo技术代理
  • 别人做的网站不能用怎么办啊市场营销公司