由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Vert.x3 says "hello" to NPM users
相关主题
Vertx dependency injection 问题Re: 一个DLL的问题
Java基于DI解决runtime dependency和异步执行,有啥好轮子?为什么大部分C or C++都在linux下做?
vert.x 下使用ORM的疑问How to find the DLL dependency of an EXE file?
go这么屌?一道面试题
help abt C++谁帮忙看一下这个dll的dependencies
如何提取一个executable的所有dependency?linker problem in VC
问个两个.h文件互相include的问题should the .dll and .lib have the same name?
谁能比较一下ant和maven的有点缺点?请教一个弱弱问题,关于#include的pathname
相关话题的讨论汇总
话题: hello话题: world话题: npm话题: vertx3话题: vertx
进入Programming版参与讨论
1 (共1页)
z****e
发帖数: 54598
1
http://vertx.io/blog/vert-x3-says-hello-to-npm-users/
13th July 2015 by pmlopes
In programming literature it has become the standard to create a hello world
program as the first example. In this
article I’ll be demonstrating how NPM users can quickly get started with
vert.x. You will see that it is not
that different and in fact it can be done using the tools you’re used to.
Note that although we are using NPM we are
not relying on node.js, all javascript code runs on the JVM.
Hello World Examples
Here are four simple hello world examples. The comments in the code explain
how the code works and the text around it
explain what it does and how to test it.
Hello Console
This example is about as plain as it can get. It prints the words “Hello
World“ to the terminal. If you’re a
javascript developer you should be already used to npm and know that you
always start a project with the file
package.json:
{
"name": "vertx3-hello-console",
"private": true,
"dependencies": {
"vertx3-min": "3.0.0-1"
},
"scripts": {
"start": "./node_modules/.bin/vertx run server.js"
}
}
Note that we have a dependency wich is obvious vert.x now note that there
are 3 flavours of this dependency:
min
base
full
According to your needs you can pick a different flavour, since for a simple
hello world we only need the minimal that
is the one we add to the dependency property.
Now we need to do a simple hello app, we will call this file “server.js“:
// Call the console.log function.
console.log("Hello World");
You can run this by executing:
npm install
npm start
The first command retrieve the vert.x stack while the seconds starts your
program.
Hello HTTP
I’d guess that while it’s not the only use case for vert.x, most people
are using it as a web application platform. So
the next example will be a simple HTTP server that responds to every request
with the plain text message “Hello World“
server.js:
vertx.createHttpServer()
.requestHandler(function (req) {
req.response()
.putHeader("content-type", "text/plain")
.end("Hello World!");
}).listen(8080);
Now you can reuse the same package.json we’ve just defined in the previous
section and start the server with
npm start. Once the server starts you can open a browser to http://localhost:8080 and enjoy the message.
Hello TCP
Vert.x also makes an excellent TCP server, and here is an example that
responds to all TCP connections with the
message “Hello World” and then closes the connection server.js:
var server = vertx.createNetServer();
server.connectHandler(function (socket) {
socket.write("Hello World!n");
socket.close();
});
server.listen(7000, "localhost");
Again reuse the previous package.json and test it by doing telnet localhost
7000.
Hello Web
Often you won’t be using vert.x built-in libraries because they are
designed to be very low level. This makes vert.x
quick, nimble, and easy to maintain, but if you are planning to build a
complex application you want some productivity
and rely on a simple web framework. For this specific case there is vert.x
web,
a simple, yet productive framework, to build fast web application with
routing, template
rendering, lots of middleware etc…usually not enough to get started on a
real world application. This example shows an
HTTP server that responds with “Hello World” to all requests to “/“ and
responds with a 404 error to everything else
server.js:
var Router = require("vertx-web-js/router");
var server = vertx.createHttpServer();
var router = Router.router(vertx);
router.get("/").handler(function (ctx) {
// This handler will be called for "/" requests
var response = ctx.response();
response.putHeader("content-type", "text/plain");
// Write to the response and end it
response.end("Hello World!");
});
server.requestHandler(router.accept).listen(8080);
In order to test this, you will need to install the vertx3-full stack. There
are two ways to do this. You can either
install it globally npm install -g vertx3-full or add it as a dependency to
our package.json as we have done before,
for example package.json:
{
"name": "vertx3-hello-web",
"private": true,
"dependencies": {
"vertx3-full": "3.0.0-1"
},
"scripts": {
"start": "./node_modules/.bin/vertx run server.js"
}
}
That’s it for now, Hopefully this will help you get started working with
vert.x!
e***i
发帖数: 231
2
赵老师是Vert.x3的作者吧?
z****e
发帖数: 54598
3

no
水平达不到,我怀疑这里有没有人有被vert.x组看上的实力
vert.x的作者很有实力,一般至少是apache top level project的lead吧
我看那几个core developers都是这个级别的

【在 e***i 的大作中提到】
: 赵老师是Vert.x3的作者吧?
x***4
发帖数: 1815
4
我觉得vertx的code非常清楚。

【在 z****e 的大作中提到】
:
: no
: 水平达不到,我怀疑这里有没有人有被vert.x组看上的实力
: vert.x的作者很有实力,一般至少是apache top level project的lead吧
: 我看那几个core developers都是这个级别的

z****e
发帖数: 54598
5

我觉得vert.x的文档更出彩
不过他们的code里面有大量的注释
直接看javadoc其实就能看懂了

【在 x***4 的大作中提到】
: 我觉得vertx的code非常清楚。
x*******6
发帖数: 262
6
请问赵老师vertx的application一般怎么在server上跑?看它的例子好像java -jar 就
可以运行了,查了下可以把一个jar打包成后台service跑,是这样吗
z****e
发帖数: 54598
7
http://github.com/vert-x3/vertx-examples/blob/master/README.ado
好几种方法
一种是设置path之后,用vertx命令行跑
简单说就是安装jdk,把jdk和vert.x的文件夹放到path里面去
然后vert.x run ***.java/groovy/ruby etc.
还有一种就是用代码方式调用,需要拿到Vertx的obj
然后从你的代码运行vert.x,怎么运行你自己的代码那就看你自己了
你可以写一个main函数,然后run
如果你想用java -jar的方式的话,需要把vert.x打包成jar
这个是x3新增的功能,你可以试试
这样做你可能需要maven或者gradel
但是不需要把vert.x的目录放到path中去了

【在 x*******6 的大作中提到】
: 请问赵老师vertx的application一般怎么在server上跑?看它的例子好像java -jar 就
: 可以运行了,查了下可以把一个jar打包成后台service跑,是这样吗

c*******9
发帖数: 9032
8
如果是http web为主的项目,Vert.x3 和sevlet开发难易程度差不多吧, 能代替多少
struts+spring+hibernate的功能?

【在 z****e 的大作中提到】
: http://github.com/vert-x3/vertx-examples/blob/master/README.ado
: 好几种方法
: 一种是设置path之后,用vertx命令行跑
: 简单说就是安装jdk,把jdk和vert.x的文件夹放到path里面去
: 然后vert.x run ***.java/groovy/ruby etc.
: 还有一种就是用代码方式调用,需要拿到Vertx的obj
: 然后从你的代码运行vert.x,怎么运行你自己的代码那就看你自己了
: 你可以写一个main函数,然后run
: 如果你想用java -jar的方式的话,需要把vert.x打包成jar
: 这个是x3新增的功能,你可以试试

z****e
发帖数: 54598
9

struts现在已经没多少人在用了
我看struts一些子项目都停止开发了
基本上被spring mvc所取代
现在比较常见的common legacy组合应该是
spring + tomcat + hibernate
这几个都比较难替代,虽然vert.x效率要高点
但是legacy code应该都不会改
vert.x主要的竞争领域在于web service部分
以及将来很快就要到来的streaming部分
借用rxjava的推力,应该vert.x的应用领域会得到进一步的拓展
vert.x跟spring mvc, node.js, akka甚至ejb这些都有竞争
甚至还把手伸向了hdfs,script language support这种领域
但是又都不完全重合,所以vert.x的前景会比较看好
因为随便一个领域成功了,就会把其他部分给带动起来
当有人意识到用vert.x搞一整套eco有多么轻松之后
他们就不会在回到以前那种system integration的阶段去了
因为integration是比较折腾的一件事,要对付不同系统
要测试,要写代码,比较麻烦,vert.x简单很多

【在 c*******9 的大作中提到】
: 如果是http web为主的项目,Vert.x3 和sevlet开发难易程度差不多吧, 能代替多少
: struts+spring+hibernate的功能?

z****e
发帖数: 54598
10
hibernate的功能比较难直接替代
但是你自己用hibernate在vert.x中也不难
spring的话,这个社区正在讨论,要不要做di
java程序员呼声很高,但是其他语言程序员反对
所以暂时先放下,主要是其他语言无法实现di,缺乏jee那种标准
哪怕是spring都比较少见,所以暂时先不搞,而且fp很难di
clojure这种di就怪异了,tomcat和spring mvc暂时不会有激进的改变
就像对于node.js,akka这些也都暂时不会有太大的影响
但是会逐步蚕食这些东西的市场,迟早的事
不管怎样,用vert.x就走在所有人的前面
可以接触很多新的东西,比如rxjava, streaming,docker, nosql多有趣啊
spring那些都用了很多年了,程序员需要进步进步不是?
老用lamp也会腻的
相关主题
如何提取一个executable的所有dependency?Re: 一个DLL的问题
问个两个.h文件互相include的问题为什么大部分C or C++都在linux下做?
谁能比较一下ant和maven的有点缺点?How to find the DLL dependency of an EXE file?
进入Programming版参与讨论
l**********n
发帖数: 8443
11
vert.x并发搞不过go吧。

world

【在 z****e 的大作中提到】
: http://vertx.io/blog/vert-x3-says-hello-to-npm-users/
: 13th July 2015 by pmlopes
: In programming literature it has become the standard to create a hello world
: program as the first example. In this
: article I’ll be demonstrating how NPM users can quickly get started with
: vert.x. You will see that it is not
: that different and in fact it can be done using the tools you’re used to.
: Note that although we are using NPM we are
: not relying on node.js, all javascript code runs on the JVM.
: Hello World Examples

z****e
发帖数: 54598
12

参考undertow vs go的benchmark
http://www.techempower.com/benchmarks/#section=data-r10&hw=ec2&
秒杀之
undertow的构架跟vert.x很像
都是java上的异步,我现在根本不在乎其他东东
就像看看vert.x vs undertow的结果
其他根本不是对手

【在 l**********n 的大作中提到】
: vert.x并发搞不过go吧。
:
: world

c*******9
发帖数: 9032
13
Vert.x 和nosql 有什么关系?
要说服组里的人采用新东西不容易。

【在 z****e 的大作中提到】
: hibernate的功能比较难直接替代
: 但是你自己用hibernate在vert.x中也不难
: spring的话,这个社区正在讨论,要不要做di
: java程序员呼声很高,但是其他语言程序员反对
: 所以暂时先放下,主要是其他语言无法实现di,缺乏jee那种标准
: 哪怕是spring都比较少见,所以暂时先不搞,而且fp很难di
: clojure这种di就怪异了,tomcat和spring mvc暂时不会有激进的改变
: 就像对于node.js,akka这些也都暂时不会有太大的影响
: 但是会逐步蚕食这些东西的市场,迟早的事
: 不管怎样,用vert.x就走在所有人的前面

c*******9
发帖数: 9032
14
刚看到这个
https://github.com/englishtown/vertx-cassandra

【在 c*******9 的大作中提到】
: Vert.x 和nosql 有什么关系?
: 要说服组里的人采用新东西不容易。

z****e
发帖数: 54598
15

vert.x做了一个简单的file system
理论上这个往上做的话,可以作出一个nosql db出来
就像hdfs -> hbase这种关系
或者cfs -> cassandra
另外一个关系就是vert.x对于nosql的支持比较重视
因为nosql大多数对于async的api提供得比较快
相对于db而言,所以vert.x比较快地跟nosql接轨起来
所以选择persistence的时候,选到了nosql的话
jvm上留给你的选择就不多了,比如传统的servlet+spring+hibernate这个
就不见得很合适,因为api都是同步的,vert.x都是异步的
vert.x不用马上替换,你可以一点一点加进去
vert.x3有一个很容易integrate到现有系统的方法
你看文档,只需要拿到Vertx vertx这个obj就可以做了

【在 c*******9 的大作中提到】
: Vert.x 和nosql 有什么关系?
: 要说服组里的人采用新东西不容易。

z****e
发帖数: 54598
16

官方已经有了mongo什么的api
正在做cassandra的官方驱动,稍等一段就有
这个是非官方的

【在 c*******9 的大作中提到】
: 刚看到这个
: https://github.com/englishtown/vertx-cassandra

x***4
发帖数: 1815
17
可以谈谈rxjava和streaming吗?

【在 z****e 的大作中提到】
: hibernate的功能比较难直接替代
: 但是你自己用hibernate在vert.x中也不难
: spring的话,这个社区正在讨论,要不要做di
: java程序员呼声很高,但是其他语言程序员反对
: 所以暂时先放下,主要是其他语言无法实现di,缺乏jee那种标准
: 哪怕是spring都比较少见,所以暂时先不搞,而且fp很难di
: clojure这种di就怪异了,tomcat和spring mvc暂时不会有激进的改变
: 就像对于node.js,akka这些也都暂时不会有太大的影响
: 但是会逐步蚕食这些东西的市场,迟早的事
: 不管怎样,用vert.x就走在所有人的前面

z****e
发帖数: 54598
18

streaming就是适合那种结束边界不确定但是传入的data又比较同质化的datasource
像netflix搞的视频就很像这个东东,还有message
streaming应该在将来一段时间内会逐步流行开来
以前是storm在搞,再早一点是jms,不过jms主要是无状态的dataset
fp部分用来搞streaming会比较容易
常见的map,可以直接apply func到每一个elements上去
这样你就不用for loop了,因为for loop需要知道确切的结束边界
对于streaming,没有fp那么好用,listener+fp可以比较快速地开发出东西来
那rxjava就是为了adopt这种趋势而生的东东
vert.x的reactive部分,就是直接用了rxjava
rxjava不仅仅是java,其实所有jvm上的reactive都可以用
包括rxscala, rxclojure,当然scala clojure这种天生就是fp,不需要这个一样搞
但是api标准化总是好的,还有rxgroovy
作为游戏,我觉得每一局pvp的话,其实广播的部分可以搞成streaming
用tcp建立稳定连接,然后发送streams到每一个clients上去
udp应该用不到,不过可能server & client的连接用streaming在gaming上有些早
但是server内部,用streaming是比较合理的,因为内部网一般比较稳定
可以将vert.x跟nosql用streaming api连接起来,或者log之类的
比如你可以用kafka,跟vert.x对接,尤其是可以直接对接他们的bus
这样msg可以看作是一个stream,不过这一块很新,发展还需要时间
但是不管怎样,vert.x对于这些新生事物,都采纳得很快,优势就在于此

【在 x***4 的大作中提到】
: 可以谈谈rxjava和streaming吗?
z****e
发帖数: 54598
19
所以我个人认为,技术革新已经逐步转移到了netflix这家公司上去
rxjava这种神奇的东西,不是google之类的做出来的
反而是netflix在搞,而且netflix很喜欢优化aws
做各种傻瓜化折腾aws的工具,我相信用不了多久
netflix的这些傻瓜化的工具会逐步流行开来
rxjava的接口什么比较标准,scala的很多东西就不那么标准
就这个差别,本质上原理是一样的
vert.x在rxjava的基础之上做了pump那些,不过我还没怎么用过
不确定这个到底怎么搞,只是听以前做scala的人提起,说大并发时候需要这个东西
z****e
发帖数: 54598
20
用了vert.x你可以接触到几乎所有的新生事物,比如reactive,比如async,比如nosql
,比如file system,比如rxjava,比如streaming,好好玩啊,怎么能不喜欢这个东西
,这个版面上讨论的一切,都有一个小部分在搞,除非你做非常底层的东西,比如go那
些,那这个没办法,毕竟jvm封装到了这个level,不可能再回头去搞这些底层的东东,
其他应用层面的新生事物,vert.x的人都跟进得很快,实际上rxjava那个本杰明也对
vert.x有感觉,文档中写到过不少,当然java就这样,你单独用rxjava也是完全可以的
,就像spring跟hibernate没有必要捆绑到一块去一样
1 (共1页)
进入Programming版参与讨论
相关主题
请教一个弱弱问题,关于#include的pathnamehelp abt C++
一道面试怪题C++. (转载)如何提取一个executable的所有dependency?
C++ interdependence question问个两个.h文件互相include的问题
How to link math library in VC2005?谁能比较一下ant和maven的有点缺点?
Vertx dependency injection 问题Re: 一个DLL的问题
Java基于DI解决runtime dependency和异步执行,有啥好轮子?为什么大部分C or C++都在linux下做?
vert.x 下使用ORM的疑问How to find the DLL dependency of an EXE file?
go这么屌?一道面试题
相关话题的讨论汇总
话题: hello话题: world话题: npm话题: vertx3话题: vertx