本文介绍了是否可以使用非函数式语言构建反应式应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解是否可以使用非函数式语言来实现响应式应用程序宣言背后的原则.

I would like to understand if the principles behind the Reactive Application manifesto can be achieved using a non-functional language.

有人说,由于 FP 使用不可变状态和免费副作用函数,因此它们更容易实现并发、分布式和弹性系统.

Some people say that since FP use immutable states and free side-effects functions, they are easier to implement concurrent, distributed and resilient systems.

但是我们如何使用 Java 来实现这一点?

But how can we achieve that using Java for example?

有一些框架,例如 Apache Camel,有一些组件可以使用,例如 Camel RXCamel SEDA.

There are some frameworks like Apache Camel, that have some components to work with, like Camel RX, and Camel SEDA.

这些框架足够了吗?

我会尽量澄清我的问题:

我认为反应式编程是新的编程范式,而新的编程范式需要新的工具和框架.

I think of reactive programming as new programming paradigm, and a new programming paradigm requires new tools and frameworks.

函数式语言处理对象的方式不同,这就是为什么有很多关于 FRP 处理基于事件和异步事物的文章的原因.

Functional languages deals with objects differently, that's why there's a lot of articles about FRP working with things event-based and asynchronously.

但是现在,回到 Java 或其他面向对象的语言,让我们在 Web 应用程序中思考:

But now, backing to Java, or other Object Oriented language, let's think in a Web Application:

  1. 我们如何创建一个利用好基于事件的前端.
  2. 这些事件然后以平稳的方式将信息异步传递到后端.
  3. 后端可以轻松扩展并具有弹性.

我知道可以使用 java、servlet 和 EJB 创建一个满足这些要求的应用程序,但我的问题是,我们可以做不同的事情吗?更接近反应式方法?

I know that is possible to create an application that accomplish these requirements using java, and servlets, and EJBs, but my question is, can we do it differently?More close to a reactive approach?

我是这样想的:

  • 前端的一个不错的ajax框架,使得与后端的信息传递"顺畅.
  • 在后端,一种使用框架或库(Camel SEDA 或 Camel RX)并行执行事物的方法.

您认为这是一个好方法吗?

Do you think this is a good approach?

推荐答案

响应式编程并不新鲜,但对大多数人来说却是陌生的.它只是自 1960 年代以来一直存在的数据流的另一个名称.响应式宣言只是描述数据流和响应式编程的最佳品质的方式.

Reactive Programming is not new, but it is new to most people. It is simply another name for dataflow that has been around since the 1960's. The Reactive Manifesto is just way to describe the best qualities of Dataflow and Reactive Programming.

当然不需要函数式语言,也不需要庞大的库.我已经实现了许多数据流系统.它们中的大多数更像是一个辅助函数的集合,而不是大多数人称之为库"的东西.这实际上取决于您想要系统中的功能类型.

A functional language is certainly not needed nor is a huge library. I've implemented many dataflow systems. Most of them are more of a collection of helper functions than what most would call a "library." It really depends what type of features you want in the system.

数据流是一个非常广泛"的话题.该系统可以包括许多不错的功能,也可以只包含基础功能.数据流的核心是数据控制执行.这与控制流"(在 C# 和 Java 等所有主流语言中使用)形成对比,在控制流"中您可以告诉计算机何时、何地以及如何处理数据.最常见的数据流形式是管道模型……一系列盒子(或节点)通过链接(又名管道、电线或弧线)按顺序相互连接.

Dataflow is a very "wide" topic. The system could include many nice-to-have features or it could just have the basics. The core of dataflow is that the data controls execution. This is in contrast to "contol-flow" (used in all mainstream languages like C# and Java) where you tell the computer when, where and how to process the data. The most common form of dataflow is the Pipeline model... a series of boxes (or nodes) connected sequentially to one another with links (aka pipes, wires or arcs).

我刚刚开始研究可用于 Java 数据流编程的库,所以我现在不能给你一个具体的答案.似乎 RxJava 是 Java 中数据流的当前名牌",所以我将从那里开始.在我即将出版的书(http://DataflowBook.com)中,我将用一整节来介绍常用语言的可用数据流库,包括 Java.

I have just started to examine the libraries available for Java dataflow programming so I can't give you a specific answer right now. It seems that RxJava is current "name-brand" for dataflow in Java so I would start there. In my upcoming book (http://DataflowBook.com) I will devote a whole section to the available dataflow libraries in common languages, including Java.

这篇关于是否可以使用非函数式语言构建反应式应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 16:51