简体   繁体   English

将结果从Spark Stream提取到Java对象

[英]Extract result from Spark Stream into Java Object

Currently I have integrated Spark Stream with Kafka in Java and able to aggregate the stats. 目前,我已经在Java中将Spark Stream与Kafka集成在一起,并且能够汇总统计信息。 However, I cannot figure out a way to store the result into a Java object so I can pass this object with the result around with different methods/classes without storing them into database. 但是,我无法找到一种将结果存储到Java对象中的方法,因此我可以使用不同的方法/类将结果与该对象一起传递,而无需将其存储到数据库中。 I have spent quite amount of time searching for tutorial/examples online but all of them are end up with using print() to display the result in console. 我花了很多时间在网上搜索教程/示例,但是所有这些最终都使用print()在控制台中显示了结果。 However, what I am trying to do is to return these results JSON string when users call a rest-api endpoint. 但是,我试图做的是当用户调用rest-api端点时返回这些结果JSON字符串。

Is it possible that I can have these results in memory and pass them around with different methods, or I need to store them into database first and fetch them from there as needed? 是否可以将这些结果存储在内存中并以不同的方法传递给它们,或者我需要先将它们存储到数据库中,然后根据需要从那里获取它们?

If I got you right you want consume your results from Spark Streaming via Rest APIs. 如果我答对了,您想通过Rest API消耗Spark Streaming的结果。

Even if there are some ways to directly accomplish this (eg using Spark SQL/Thrift server) I would separate these two tasks. 即使有一些方法可以直接完成此任务(例如,使用Spark SQL / Thrift服务器),我也会将这两个任务分开。 Else if you're Spark Streaming process fails, your service/REST-API layer will fail too. 否则,如果您的Spark Streaming过程失败,那么您的服务/ REST-API层也会失败。

Thus it has its advantages to separate these two layers. 因此,将这两层分开具有其优点。 You are not forced to use a classical database. 您没有被迫使用经典数据库。 You could implement a service, which implements/uses JCache and send your results of the Spark streaming process to it. 您可以实现一个服务,该服务实现/使用JCache并将Spark流处理的结果发送给它。

提取列表<object> Java / Spring Boot 查询结果<div id="text_translate"><p>我想在查询中获取结果的值。</p><p> 这是我的查询/存储库文件:</p><pre> @Query("select p.name, p.contact_no, p.email_address, p.time_submitted, p.date_due from Application p where p.application_number like?1") List<Application> getApplicationSummaryInfo(String application_number);</pre><p> 服务:</p><pre> public List<Application> getApplicationSummaryInfo(String application_number);</pre><p> 服务实现:</p><pre> @Override public List<Application> getApplicationSummaryInfo(String application_number) { return (List<Application>)applicationRepository.getApplicationSummaryInfo(application_number); }</pre><p> Controller:</p><pre> List<Application> app_info = applicationService.getApplicationSummaryInfo(application_no);</pre><p> 我只知道如何使用 foreach 在 jsp 文件中访问它。 但我想访问我的 controller 文件中的字段。</p><p> 我试过这样做:</p><pre> List<Application> app_info = applicationService.getApplicationSummaryInfo(application_no); System.out.println(app_info.get(0));</pre><p> 我得到这个结果:</p><pre> [Ljava.lang.Object;@28bf8e6e</pre><p> 然后我尝试获取确切的“名称”字段值</p><pre>List<Application> app_info = applicationService.getApplicationSummaryInfo(application_no); System.out.println(app_info.get(0).getName());</pre><p> 但我得到这个错误</p><pre>java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class com.pckg_name.model.Application ([Ljava.lang.Object; is in module java.base of loader 'bootstrap'; com.rtc_insurance.model.Application is in unnamed module of loader 'app')</pre><p> 真的希望你能帮助我。 谢谢!</p></div></object> - Extract List<Object> result from query in Java / Spring Boot

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java 8 Stream从过滤结果中获取对象 - Java 8 Stream get object from filter result Java Streams - 将流结果从一个对象转换为另一个 - Java Streams - Transform stream result from an object to another Java 8:从流中提取子流 - Java 8: extract a substream from a stream 提取列表<object> Java / Spring Boot 查询结果<div id="text_translate"><p>我想在查询中获取结果的值。</p><p> 这是我的查询/存储库文件:</p><pre> @Query("select p.name, p.contact_no, p.email_address, p.time_submitted, p.date_due from Application p where p.application_number like?1") List<Application> getApplicationSummaryInfo(String application_number);</pre><p> 服务:</p><pre> public List<Application> getApplicationSummaryInfo(String application_number);</pre><p> 服务实现:</p><pre> @Override public List<Application> getApplicationSummaryInfo(String application_number) { return (List<Application>)applicationRepository.getApplicationSummaryInfo(application_number); }</pre><p> Controller:</p><pre> List<Application> app_info = applicationService.getApplicationSummaryInfo(application_no);</pre><p> 我只知道如何使用 foreach 在 jsp 文件中访问它。 但我想访问我的 controller 文件中的字段。</p><p> 我试过这样做:</p><pre> List<Application> app_info = applicationService.getApplicationSummaryInfo(application_no); System.out.println(app_info.get(0));</pre><p> 我得到这个结果:</p><pre> [Ljava.lang.Object;@28bf8e6e</pre><p> 然后我尝试获取确切的“名称”字段值</p><pre>List<Application> app_info = applicationService.getApplicationSummaryInfo(application_no); System.out.println(app_info.get(0).getName());</pre><p> 但我得到这个错误</p><pre>java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class com.pckg_name.model.Application ([Ljava.lang.Object; is in module java.base of loader 'bootstrap'; com.rtc_insurance.model.Application is in unnamed module of loader 'app')</pre><p> 真的希望你能帮助我。 谢谢!</p></div></object> - Extract List<Object> result from query in Java / Spring Boot Java 8 Stream从Map中提取数据 - Java 8 Stream extract datas from Map Java如何从电影中提取音频流 - Java how to extract audio stream from movie 从HTTP事件流Java中提取数据 - Extract data from HTTP event stream Java 如何使用 Stream 从 Java 中的字符串中提取三元组 - how to extract a trigrams from a string in Java with Stream 从单个 Java stream 中提取多个值 - Extract multiple values from a single Java stream 从Java的传输流中提取信息 - Extract information from a Transport Stream in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM