本文介绍了Jolie 和 Spring Boot 注释 - 怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我目前正在致力于在 Spring Boot 中创建基本的 Jolie 支持.Jolie 是一种微服务语言,它在底层是基于 Java,但具有非常不同的语法(这当然只是我的概念 - 我认为这项任务可能如何完成,但话说回来 - 存在 Spring Boot 注释的问题.

解决方案

您将不得不在 Spring Boot 应用程序内部从 Java 运行 Jolie 解释器.例如,参见 http://fmontesi.github.io/2015/01/30/running-jolie-inside-of-java.html

在您的 Jolie 服务中声明一个本地内存输入端口:https://jolielang.gitbook.io/docs/locations/local

然后,您可以通过调用 interpreter.commCore().getLocalCommChannel() 来访问在本地输入端口上公开的操作,这将返回一个可用于发送和接收的通信通道对象给朱莉口译员的消息.

这是一个快速而肮脏的例子(你可能想更好地处理未来和异常),我发送一个包含整数x"的值:

Value v = Value.create();v.setFirstChild("x", 5);CommMessage request = CommMessage.createRequest( "yourOperationName", "/", v );LocalCommChannel c = interpreter.commCore().getLocalCommChannel();试试{c.发送(请求);CommMessage response = c.recvResponseFor( request ).get();如果(响应.isFault()){抛出 response.fault();}返回 response.value();} catch( ExecutionException | InterruptedException | IOException e ) {throw new FaultException(Constants.IO_EXCEPTION_FAULT_NAME, e);}

除了 Jolie 的解释器和 Java 服务的内部结构之外,这个 API 实际上仍然没有被大量使用,所以总是欢迎评论让它更友好.

PS:你这样做的动机是什么?如果您的目标是使用 Jolie 制作微服务,那么将您需要的功能添加为 Jolie 库是不是比将 Jolie 添加到 Spring Boot"更容易?

I am currently working on creating basic Jolie support in Spring Boot. Jolie is a microservice language, which under the hood - is based on Java, but has very different syntax(example). Thanks to JavaService class, which comes with Jolie, it is possible to take class/method functionalities from Java and its libraries, and embed them in Jolie. I would like to know how can the same be achieved for annotations and functionalities that are implemented through them. Can it be done with JavaService, too? Or do I have to write my own annotation parsing for Jolie?

A simple example of behaviour I'd like to achieve is a @SpringBootApplication which runs a "Hello world" @RestController, like here(points 2.3 and 2.4). Ideally, similar program in Jolie would look somewhat like below:

interface SpringAppInterface {
    OneWay:
      run(string)
}

outputPort SpringApplication {
    Interfaces: SpringAppInterface
}

embedded {
    Java:
      "joliex.spring-boot.SpringApplicationService" in SpringApplication
}

@SpringBootApplication
main {
    run@SpringApplication(args)
}

where SpringApplicationService extends the JavaService class and is embedded in Jolie. And now a @RestController:

inputPort SpringTestService {
    ...
}

@RestController
main {
    @RequestMapping("/hello")
    hello(void)(response) {
        response = "hello world"
    }
}

That is an ideal way and it presents well a behaviour I want to achieve. And to better show a real use of JavaService class - here is its implementation of standard Java Math class and here - its embedment in Jolie.

On a side note: I wonder if it's possible to run whole Spring Boot logic on the JavaService side, so for example I would have a JavaService already annotated with @SpringBootApplication, a JavaService annotated @RestController etc.


Edit:
As I said - I want to create Jolie support in Spring Boot, so in the end a Jolie developer would be able to include, for example "spring-boot.iol", and be able to create Spring Boot-based Jolie programs. "spring-boot.iol" I imagine would be similar to all existing include files, like "console.iol", "math.iol" etc., and it would embed a JavaService - let's call it "SpringBootService". Now this SpringBootService would take functionalities from Spring Boot libraries to allow Jolie to use them. That way - with inclusion of some *.iol files - a Jolie program would indeed implement Spring Boot functionalities and run Spring Boot applications.That is of course only my concept - how I think this task might be done, but then again - there is the problem of Spring Boot annotations.

解决方案

You're going to have to run the Jolie interpreter from Java, inside of your Spring Boot application. See, for example, http://fmontesi.github.io/2015/01/30/running-jolie-inside-of-java.html

Declare a local memory input port in your Jolie service: https://jolielang.gitbook.io/docs/locations/local

You can then reach the operations exposed on the local input port by calling interpreter.commCore().getLocalCommChannel(), which will return you a communication channel object that you can use to send and receive messages to the Jolie interpreter.

Here's a quick and dirty example (you probably want to handle the future and exceptions better) where I send a value containing an integer "x":

Value v = Value.create();
v.setFirstChild( "x", 5 );
CommMessage request = CommMessage.createRequest( "yourOperationName", "/", v );
LocalCommChannel c = interpreter.commCore().getLocalCommChannel();
try {
    c.send( request );
    CommMessage response = c.recvResponseFor( request ).get();
    if ( response.isFault() ) {
        throw response.fault();
    }
    return response.value();
} catch( ExecutionException | InterruptedException | IOException e ) {
    throw new FaultException( Constants.IO_EXCEPTION_FAULT_NAME, e );
}

This API is actually still not used a lot outside of the internals of the Interpreter and Java services for Jolie, so comments on making it friendlier are always welcome.

PS: What's your motivation for this? If your objective is to make a microservice with Jolie, isn't it just easier to add the functionalities you need as a Jolie library instead of "adding Jolie to Spring Boot"?

这篇关于Jolie 和 Spring Boot 注释 - 怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 07:14