Node calls Java sample code

JAVA side As a service provider, Dubbo implementation service and exposes the exposure service through Dubbo Hessian; Node side as a service consumer, call the Java end through Node-Hessian.

JAVA end

Service interface

 package com.myxin.paas.ssb; public interface testservice {/ ** * test: No argument, no reference. * / void test (); / ** * Test: native type parameters and return values. * @Param i * @return * / string test0 (INT i); / ** * Test: No argument, custom type return value. * @Return * / result test1 (); / ** * Test: Customized type parameters, no reference. * @Param arg * / void test2 (arg arg); / ** * Test: Custom parameters, custom return value. * @Param arg * @Return * / result TEST3 (Final Arg);}   Custom parameter class 

package com.yuanxin.paas.ssb; import; Public Class Arg IMPLEments Serializable{Private INT i; public int GETI () {RETURN I; PUBLIC VOID SETI (INT I) {this.i = i;}}
 Custom Return Value Class   
Package com.yuanxin.paas.ssb; import; public class result estiments serializable {private int i; private string string; public int GETI (Public Int Get) () PUBLIC INT GETI (PUBLIC INT GETI) ) {RETURN I;} public void seti (INT i) {this.i = i;} public string getString () {Return string; String String (String string) {this.string = string;}}

DUBBO configuration is omitted.
Install Node-Hessian:

NPM Install Hessian-Proxy

Call service interface
   VAR Proxy = Require ('HESSIAN-Proxy'). Proxy; Var Proxy = New Proxy ('', '', '' , Proxy.invoke ('Test', NULL, FUNCTION (ERR, Reply) {Console.log ('Test:' + Reply);}; Proxy.Invoke ('Test0', [25], Function Err, reply.log ('test0:' + json.stringify (reply);}) proxy.invoke ('Test1', Null, Function (Err, Reply) {if (err) {Console.log 'test1:' + err;} console.log ('test1:' + json.stringify);}) VAR argfortest2 = {i: 2}; argfortest2 .__ type__ = 'com.yuanxin.paas.ssb. Arg '; proxy.invoke (' Test2 ', [argfortest2], function (err, reply) {if (err) {console.log (' test2: '+ err);} console.log (' Test2: '+ JSON .Stringify (reply);}) var argfortest3 = {i: 3}; argforTEST3 .__ type__ = 'com.yuanxin.paas.ssb.arg'; proxy.invoke ('Test3', [argfortest3], function (err, reply) {if (err) {console.log ('test3: + ERR );} console.log ('test3:' + json.stringify (reply));}) 
Operation result

JAVA end


Dubbo is very good, providing HESSIAN The support of the novel agreement; Node call is also very simple, but there are still a few points to pay attention to:

The interface method cannot be overloaded (the method in the interface must use different method names) Node调用Java的示例代码

Customized Namespace Services with consumer terminals (com.yuanxin.paas.ssb.Arg)

server custom type requires serialization interface (

Node调用Java的示例代码 Try to use a simple custom type structure (avoid nesting)

The above is all the content of this article, I hope that everyone’s learning is helpful, I hope everyone will support Tumi cloud.

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment