Spring Web Flux React 前端 angularjs

Spring Web Flux React front end with angularjs

我是 spring 网络流量反应技术的新手,但按照教程,我开发了我的第一个 "hello world" 服务。现在我正在尝试使用 angularjs 1.5.9 作为前端库来连接此服务。

问题是我找不到用于使用 AngularJS 调用此简单服务的示例、库或模块。所有示例都与 AngularJS 2.

有关

有人知道任何模块吗?

谢谢

我不是 AngularJS 专家,但截至 Spring 5.0 M5, Spring WebFlux can emit Flux using text/event-stream formatted as Server-Sent Event (SSE)。任何能够理解这种格式的客户端都可以使用来自 Spring WebFlux 应用程序的流。

此外,客户端还可以请求 Content-Type 为 application/stream+json,响应将是一个 JSON 对象流,类似于 Server-Sent Events 但没有额外的格式。

这里有一些额外的资源:

这个库值得一试:angular-oboe

找到了一个可能的实现 here,表明从 AngularJS 应用程序使用 SSE 可以像以下一样简单:

angular.module('foo', []).factory('sse', function($rootScope) {
  var sse = new EventSource('/stream');
  return {
    addEventListener: function(eventName, callback) {
      sse.addEventListener(eventName, function() {
        var args = arguments;
        $rootScope.$apply(function () {
          callback.apply(sse, args);
        });
      });
    }
  };
});

function FooCtrl($scope, sse) {
  $scope.foos = [];
  sse.addEventListener('message', function (e) {
    $scope.foos.push({value: e.data});
  });
}