• flink java代码在客户端运行


    要在本地开发环境运行flink代码,需要在pom中添加:

    1. <dependency>
    2. <groupId>org.apache.flink</groupId>
    3. <artifactId>flink-clients_2.12</artifactId> <!-- 2.12是flink依赖的scala的版本,依据自己项目的scala版本进行修改 -->
    4. <version>${flink.version}</version>
    5. </dependency>

    否则直接执行main函数会报如下错误:

    1. Exception in thread "main" org.apache.flink.runtime.client.JobExecutionException: Job execution failed.
    2. at org.apache.flink.runtime.jobmaster.JobResult.toJobExecutionResult(JobResult.java:144)
    3. at org.apache.flink.runtime.minicluster.MiniClusterJobClient.lambda$getJobExecutionResult$2(MiniClusterJobClient.java:117)
    4. at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:616)
    5. at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:591)
    6. at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488)
    7. at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:1975)
    8. at org.apache.flink.runtime.rpc.akka.AkkaInvocationHandler.lambda$invokeRpc$0(AkkaInvocationHandler.java:237)
    9. at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:774)
    10. at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:750)
    11. at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488)
    12. at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:1975)
    13. at org.apache.flink.runtime.concurrent.FutureUtils$1.onComplete(FutureUtils.java:1061)
    14. at akka.dispatch.OnComplete.internal(Future.scala:264)
    15. at akka.dispatch.OnComplete.internal(Future.scala:261)
    16. at akka.dispatch.japi$CallbackBridge.apply(Future.scala:191)
    17. at akka.dispatch.japi$CallbackBridge.apply(Future.scala:188)
    18. at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
    19. at org.apache.flink.runtime.concurrent.Executors$DirectExecutionContext.execute(Executors.java:73)
    20. at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:72)
    21. at scala.concurrent.impl.Promise$DefaultPromise.$anonfun$tryComplete$1(Promise.scala:288)
    22. at scala.concurrent.impl.Promise$DefaultPromise.$anonfun$tryComplete$1$adapted(Promise.scala:288)
    23. at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:288)
    24. at akka.pattern.PromiseActorRef.$bang(AskSupport.scala:573)
    25. at akka.pattern.PipeToSupport$PipeableFuture$$anonfun$pipeTo$1.applyOrElse(PipeToSupport.scala:22)
    26. at akka.pattern.PipeToSupport$PipeableFuture$$anonfun$pipeTo$1.applyOrElse(PipeToSupport.scala:21)
    27. at scala.concurrent.Future.$anonfun$andThen$1(Future.scala:536)
    28. at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:33)
    29. at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:33)
    30. at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
    31. at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
    32. at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
    33. at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
    34. at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:85)
    35. at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)
    36. at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)
    37. at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:44)
    38. at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    39. at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    40. at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    41. at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
    42. Caused by: org.apache.flink.runtime.JobException: Recovery is suppressed by NoRestartBackoffTimeStrategy
    43. at org.apache.flink.runtime.executiongraph.failover.flip1.ExecutionFailureHandler.handleFailure(ExecutionFailureHandler.java:118)
    44. at org.apache.flink.runtime.executiongraph.failover.flip1.ExecutionFailureHandler.getFailureHandlingResult(ExecutionFailureHandler.java:80)
    45. at org.apache.flink.runtime.scheduler.DefaultScheduler.handleTaskFailure(DefaultScheduler.java:233)
    46. at org.apache.flink.runtime.scheduler.DefaultScheduler.maybeHandleTaskFailure(DefaultScheduler.java:224)
    47. at org.apache.flink.runtime.scheduler.DefaultScheduler.updateTaskExecutionStateInternal(DefaultScheduler.java:215)
    48. at org.apache.flink.runtime.scheduler.SchedulerBase.updateTaskExecutionState(SchedulerBase.java:666)
    49. at org.apache.flink.runtime.scheduler.SchedulerNG.updateTaskExecutionState(SchedulerNG.java:89)
    50. at org.apache.flink.runtime.jobmaster.JobMaster.updateTaskExecutionState(JobMaster.java:446)
    51. at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
    52. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    53. at java.lang.reflect.Method.invoke(Method.java:498)
    54. at org.apache.flink.runtime.rpc.akka.AkkaRpcActor.handleRpcInvocation(AkkaRpcActor.java:305)
    55. at org.apache.flink.runtime.rpc.akka.AkkaRpcActor.handleRpcMessage(AkkaRpcActor.java:212)
    56. at org.apache.flink.runtime.rpc.akka.FencedAkkaRpcActor.handleRpcMessage(FencedAkkaRpcActor.java:77)
    57. at org.apache.flink.runtime.rpc.akka.AkkaRpcActor.handleMessage(AkkaRpcActor.java:158)
    58. at akka.japi.pf.UnitCaseStatement.apply(CaseStatements.scala:26)
    59. at akka.japi.pf.UnitCaseStatement.apply(CaseStatements.scala:21)
    60. at scala.PartialFunction.applyOrElse(PartialFunction.scala:127)
    61. at scala.PartialFunction.applyOrElse$(PartialFunction.scala:126)
    62. at akka.japi.pf.UnitCaseStatement.applyOrElse(CaseStatements.scala:21)
    63. at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:175)
    64. at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:176)
    65. at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:176)
    66. at akka.actor.Actor.aroundReceive(Actor.scala:517)
    67. at akka.actor.Actor.aroundReceive$(Actor.scala:515)
    68. at akka.actor.AbstractActor.aroundReceive(AbstractActor.scala:225)
    69. at akka.actor.ActorCell.receiveMessage(ActorCell.scala:592)
    70. at akka.actor.ActorCell.invoke(ActorCell.scala:561)
    71. at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:258)
    72. at akka.dispatch.Mailbox.run(Mailbox.scala:225)
    73. at akka.dispatch.Mailbox.exec(Mailbox.scala:235)
    74. ... 4 more
    75. Caused by: java.net.ConnectException: Connection refused: connect
    76. at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    77. at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
    78. at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)
    79. at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)
    80. at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200)
    81. at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:162)
    82. at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394)
    83. at java.net.Socket.connect(Socket.java:606)
    84. at org.apache.flink.streaming.api.functions.source.SocketTextStreamFunction.run(SocketTextStreamFunction.java:104)
    85. at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:110)
    86. at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:66)
    87. at org.apache.flink.streaming.runtime.tasks.SourceStreamTask$LegacySourceFunctionThread.run(SourceStreamTask.java:267)

    flink1.12的java具体实现代码:https://gitee.com/leidengyan/flink-java-1.12.7

    参考:https://www.cnblogs.com/jia-tong/p/16615412.html

  • 相关阅读:
    行业追踪,2023-10-09
    docker保存镜像、打包tar、加载tar镜像
    【机器学习】李宏毅——Anomaly Detection(异常检测)
    从零开始学YC-Framework之鉴权
    GoLong的学习之路,进阶,标准库之并发(context)补充并发三部曲,你真的明白context吗?
    利用熵权法进行数值评分计算——算法过程
    Java——》对象如何进行拷贝
    计算机组成原理——第一章 计算机系统概论——复习逻辑图
    J41H-64C蒸汽截止阀型号解析
    站群服务器的特性和好处是什么
  • 原文地址:https://blog.csdn.net/leidengyan/article/details/132890297