Java + NodeJS通过socket进行通信:糟糕的想法? [英] Java + NodeJS communicating via socket: Bad Idea?

查看:126
本文介绍了Java + NodeJS通过socket进行通信:糟糕的想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢NodeJS的一些功能,特别是JQuerification,通过socket.io,视图和css引擎的websocket兼容性,我不能用于JSP(当然还有异步调用)。至少,据我所知。所以我打算创建我的应用程序,后端将是Java,前端将由NodeJS生成。前端表单将向NodeJS发送数据,NodeJS将通过NodeJS和Java后端之间的套接字连接将其传递给Java后端。所以NodeJS基本上就像前端和Java后端之间的中间件。

I like some features of NodeJS, particularly JQuerification, websocket compatibility via socket.io, view and css engines that I cannot use with JSP (and of course, asynchronous calls). At least, as far as I know. So I plan on creating my application where the backend will be Java, the front end will be generated by NodeJS. The front end forms will send data to NodeJS which will pass it on to the Java backend via socket connections between NodeJS and the Java backend. So NodeJS basically acts like a middleware between the front end and the Java backend.

这将是一个非常大的应用程序,我的计划看起来令人兴奋,但我会恨我的沿着这条路走下未来的自我?

This will be a pretty large application, and my plan looks exciting, but will I hate my future self for going down this route?

我的优势在于我可以拥有大量的实时图表和仪表板,并增强与表格的互动。

The advantage I have with this is that I can have a lot of real-time charts and dashboards, and enhance interactions with forms.

推荐答案

问题是你说的是通用平台。 Node.JS作为前端,JAVA作为后端。根据您的实际需要,这可能是奇妙的或可怕的。

Problem is that you speak about a generic platform. Node.JS as the front end, JAVA as backend. Depending on your real needs this can be marvellous or terrible.

那又怎样?如果他们更喜欢成熟的技术(或其他),人们会根据他们的填充做出回应。

So what? People will respond with their filling depending if they prefer mature technologies or not (or whatever).

炒作

一个人想到node.js的主要原因是炒作。就像几年前的XML数据库一样。 XML很酷,一切都必须用XML来完成......如果你注意到,没有人再谈论XML数据库了。

The primary reason a person think about node.js is hype. Like XML database a few years ago. XML was cool and everything had to be done with XML... if you notice, nobody speaks anymore about XML databases.

所以node.js是新的,博客就在附近你谈到它,再加上NoSQL数据库,它必须是最合适的。

So node.js is new, the blog near you speak about it, and coupled with a NoSQL database it must be the perfect fit.

异步IO

然后出现像async IO这样的理由。你懂? POSIX标准中的东西可能超过20年。是的,你在C课程中在学校学到的东西。顺便提一下,标准的JAVA API也支持它。实际上,如果你听node.js创建者,这不是新概念,而是仅使用异步库。大多数库都使用线程模型,不能用于异步。 Javascript本身并不是一个目标,但JS中缺少任何标准库是一个很好的起点,因为它可以避免普通的joe通过包含错误的库来搞乱一切。这不是我说的那样。

Then comes the justifications like async IO. You know? The thing that is in POSIX standard maybe for more than 20 years. Yes, what you learned at school in your C course. Incidentally, the standard JAVA API supports it too. In fact, if you listen to node.js creator, this is not the concept that is new but using only async libraries. Most libraries out there use a thread model and can't be used for async. Javascript was not a goal per se, but the lack of any standard library in JS was a good start point as it would avoid that the average joe mess up everything by including the wrong library. This not me that said that.

关键是现在有一些图书馆,但有一些是由公司支持的。我们仍然不在那里。同时,标准专业框架已经在需要时支持异步行为,如长轮询HTTP请求。请参阅Lift框架,请参阅Jetty或Tomcat对NIO的支持。

The point is there are now some libraries, but a few if any of backed by a company. We are still not there. And at the same time, the standard professional framework already support async behaviour when needed like long polling HTTP request. See Lift framework, see Jetty or Tomcat support for NIO.

与XML数据库类似。现在像Oracle这样的专业数据库确实支持XML。所以,如果你需要它,你可以保留你的标准高性能数据库...而且只能做到这一点的专业解决方案......好吧没有人记得它的名字。

Like the XML database. Now professional databases like Oracle do support XML. So in case you need it, you can keep your standard high-performance database... And the specialized solution that can only do that... Well nobody remembers even its name.

Javascript

现在是javascript。 Javascript是一个大胆的选择...因为它缺乏库。你知道还缺什么。这就是为什么你需要一个java后端!但不仅如此...... IDE对javascript的支持并不好。自动完成?勉强工作。重构?你在开玩笑吗?多线程?不。 node.js就像windows 3.1。它使用协作式多任务处理。

Now for javascript. Javascript was a bold choice... For its lack of libraries. You know what is still lacking. That why you need a java backend anyway! But not only that... IDE support for javascript is not good. Autocompletion? Barely work. Refactoring? Are you kidding? Multithreading? Nope. node.js is like windows 3.1. It uses cooperative multitasking.

结论

Node.js很有趣,但还不成熟。你自己说,你必须选择java,这样你才能做到像连接数据库这样的真实内容。此堆栈增加了另一层的复杂性。

Node.js is fun, but it is immature. You said it yourself, you have to pick java so you can do the real stuff like connecting to the database. This stack adds complexity with another layer.

要么你真的需要它,这可能是一个很好的折衷方案......要么你不需要它而你只是讨好自己......并且在你以后讨厌自己看到你花更多的时间做所有事情...只是说你有一个4层堆栈(浏览器,Node.js,JAVA,DB)而不是3.只是为了炒作和令人愉快的理论。

Either you really need it and that's maybe a good compromise... either you don't need it and you just please yourself... and hate yourself later when you see you spend more time to do everything... just to say you have a 4 layer stack (browser, Node.js, JAVA, DB) instead of 3. Just for the hype and the pleasing theory.

这篇关于Java + NodeJS通过socket进行通信:糟糕的想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆