简体   繁体   English

如何使用节点js在两个java类之间传递数据作为参数

[英]how to pass data as an arguments between two java classes using node js

i have two java classes , and i want to take the output of the first java class ,pass this data to Node Js then, finally this data must move from Node Js to the other Java class as arguments 我有两个Java类,并且我想获取第一个Java类的输出,然后将此数据传递给Node Js,最后,此数据必须作为参数从Node Js移至另一个Java类。

this the first java class 这是第一个Java类

public static void main(String[] args) {
        Random randomGenerator = new Random();
        String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());

        long timestamp = System.currentTimeMillis() / 1000;
        for (int idx = 1; idx <= 10; ++idx) {
            int randomInt = randomGenerator.nextInt(100);
            System.out.println("Generated : \t" + randomInt + "\t time:\t" + timestamp);
            //System.out.println("Generated : \t" + randomInt + "\t time:\t" + timeStamp);

        }

    }

then this is the second one 那是第二个

String msg = args[]

producer.send(new KeyedMessage("topic",msg));

i need to do this job using Node Js 我需要使用Node Js来完成这项工作

Any suggestions please 有什么建议吗

You have many approaches available. 您有许多可用的方法。 Some of them are: 他们之中有一些是:

  • Insert data into a database from JAVA, retrieve that data from Node.JS, modify it, update the database, and finally retrieve it from JAVA. 从JAVA将数据插入数据库,从Node.JS检索数据,对其进行修改,更新数据库,最后从JAVA检索数据。
  • Send an HTTP request from JAVA to Node.JS, modify it, then send a request back to JAVA and be ready to listen for it. 将JAVA的HTTP请求发送到Node.JS,对其进行修改,然后将请求发送回JAVA,并准备好侦听它。
  • Establish a socket connection between JAVA and Node.JS so they communicate between each other in real time. 在JAVA和Node.JS之间建立套接字连接,以便它们彼此之间实时通信。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM