标签: reactive-programming

VueJS 反应性日期对象

而是初学者的问题,但我在任何地方都找不到解决方案。

我有 2 个按钮可以将给定的 Date 对象增加/减少 +/- 1 天。对象已更新,但未显示更改。我发现这是因为 Date Obj 不是反​​应式的,但我没有找到解决方案或解决方法。

JSFiddle 演示

HTML:

<div id="app">
  <button @click="inc">+ 1 day</button>
  <button @click="dec">- 1 day</button>
  <br /><br />

  {{date}}
</div>
Run Code Online (Sandbox Code Playgroud)

JS/Vue:

new Vue({
  el: "#app",
  data: {
    date: new Date()
  },
  methods: {
    inc () {
        this.date.setDate(this.date.getDate() + 1)
        console.log(this.date)
    },
    dec () {
        this.date.setDate(this.date.getDate() - 1)
        console.log(this.date)
    }
  }
})
Run Code Online (Sandbox Code Playgroud)

在控制台中,日期可以很好地增加/减少,但页面上呈现的日期保持不变。有人可以帮忙吗?谢谢。

javascript date reactive-programming vue.js

3
推荐指数
1
解决办法
1496
查看次数

仅当第一次失败时才执行第二次 http 调用

尝试通过管道传输两个 Angular http 调用,仅当第一个调用失败时才执行第二个调用。

第一个电话是:

 return this.http.get<AssetGroupHistoryResponseModel>('./assets/data.json');
Run Code Online (Sandbox Code Playgroud)

如果 data.json 不存在,则会引发 404 Not Found 错误,它应该调用适当的 API:

return this.http.get<AssetGroupHistoryResponseModel>(url);
Run Code Online (Sandbox Code Playgroud)

不知道如何使用 rxjs 获得这种行为。

http reactive-programming rxjs angular

3
推荐指数
1
解决办法
1039
查看次数

用反应堆开火就忘

我的 Spring boot 应用程序中有一个如下所示的方法。

public Flux<Data> search(SearchRequest request) {
  Flux<Data> result = searchService.search(request);//this returns Flux<Data>
  Mono<List<Data>> listOfData = result.collectList();
//  doThisAsync() // here I want to pass this list and run some processing on it
// the processing should happen async and the search method should return immediately.
  return result;
}

//this method uses the complete List<Data> returned by above method
public void doThisAsync(List<Data> data) {
  //do some processing here
}

Run Code Online (Sandbox Code Playgroud)

目前,我正在使用带@Async注释的服务类doThisAsync,但不知道如何传递List<Data>,因为我不想调用block. …

spring reactive-programming spring-boot project-reactor spring-webflux

3
推荐指数
1
解决办法
4432
查看次数

.switchIfEmpty() 被急切地评估有什么意义?

即使我的流不为空,回退流也会始终创建?这样做的意图是什么?这是非常不习惯的。

另一方面, 。onErrorResume被懒惰地评估。

有人可以向我解释为什么。switchIsEmpty热切评价?

这是代码:

  public static void main(String[] args) {
    Mono<Integer> m = Mono.just(1);
    m.flatMap(a -> Mono.delay(Duration.ofMillis(5000)).flatMap(p -> Mono.empty()))
        .switchIfEmpty(getFallback())
        .doOnNext(a -> System.out.println(a))
        .block();
  }

  private static Mono<Integer> getFallback() {
    System.out.println("In Here");
    return Mono.just(5);
  }
Run Code Online (Sandbox Code Playgroud)

输出是:

In Here (printed immediately)
5 (after 5s)
Run Code Online (Sandbox Code Playgroud)

java reactive-programming project-reactor reactive

3
推荐指数
1
解决办法
2914
查看次数

NGRX 错误“调度需要一个对象,而不是它接收一个函数。如果您正在使用 createAction 函数......”

我遵循了 Youtube 上的教程,并尝试创建自己的项目,但我一直在浏览器中收到错误消息,指出 Dispatch 需要一个对象。

我的模特:

export interface Football {
  title: string;
  embed: string;
  date: string;
  url: string;
  thumbnail: string;
}
export interface State {
  footballs: Football[];
  isLoading: boolean;
  error: string;
}

export const initialState: State = {
  footballs: null,
  isLoading: false,
  error: '',
};
Run Code Online (Sandbox Code Playgroud)

行动:

export const loadAllSucceeded = createAction('[Football Api] Load All succeeded', props<{footballs: Football[]}>());

export const loadAllFailed = createAction('[Football Api] Load All succeeded', props<{error: string}>());

export const appComponentInitialized = createAction('[App Component] Initialized');

export const loadAllRequested = createAction('[App …
Run Code Online (Sandbox Code Playgroud)

reactive-programming ngrx angular

3
推荐指数
1
解决办法
1144
查看次数

Spring反应式WebClient GET json响应内容类型为“text/plain;charset=UTF-8”

我遇到了 Spring 5 反应式 WebClient 的问题,当我请求一个端点,该端点返回内容类型为“text/plain;charset=UTF-8”的格式正确的 json 响应。例外是

org.springframework.web.reactive.function.UnsupportedMediaTypeException:
Content type 'text/plain;charset=UTF-8' not supported for bodyType=MyDTOClass
Run Code Online (Sandbox Code Playgroud)

这是我提出请求的方式:

webClient.get().uri(endpoint).retrieve().bodyToFlux(MyDTOClass.class)
Run Code Online (Sandbox Code Playgroud)

编辑:标题已“正确”设置(接受、内容类型),我尝试了不同的内容类型(json、json + UTF8、纯文本、纯文本 + UTF8)组合,但没有成功。我认为问题是.bodyToFlux(MyDTOClass.class)不知道如何将“文本”翻译成MyDTOClass对象。如果我将请求更改为:

webClient.get().uri(endpoint).retrieve().bodyToFlux(String.class)
Run Code Online (Sandbox Code Playgroud)

我可以读取字符串。

编辑 2:下一个引用是从 Spring 文档中提取的(https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-codecs-jackson)

默认情况下,Jackson2Encoder和Jackson2Decoder都不支持 type 元素String。相反,默认假设是一个字符串或一系列字符串表示序列化的 JSON 内容,由CharSequenceEncoder. 如果您需要从 呈现 JSON 数组Flux<String>,请使用Flux#collectToList()并编码 Mono<List<String>>.

我认为解决方案是定义一个新的解码器/阅读器,以便将字符串转换为 MyDTOClass,但我不知道该怎么做。

reactive-programming jackson spring-boot spring-webflux

3
推荐指数
1
解决办法
6028
查看次数

Vertx 在 Quarkus vertx munity web 客户端扩展中不可用

我试图测试 vertx munity web 客户端提供的反应式 web 客户端。

我遵循了官方指南Quarkus - Getting Started with Reactive。

并在依赖项中添加了以下内容。

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy-jsonb</artifactId>
        </dependency>
        <dependency>
            <groupId>io.smallrye.reactive</groupId>
            <artifactId>smallrye-mutiny-vertx-web-client</artifactId>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

但是当我Vertx像文章中提到的那样注入时,得到了 CDI 不满意的依赖异常。Vertx不可用。

Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type io.vertx.mutiny.core.Vertx and qualifiers [@Default]
        - java member: com.example.PostResourceClient#vertx
Run Code Online (Sandbox Code Playgroud)

完整的代码在这里。

reactive-programming vert.x quarkus smallrye quarkus-rest-client

3
推荐指数
1
解决办法
757
查看次数

Spring 没有发现 ReactiveCrudRepository 被注入到其他类中

问题:

我有一个ReactiveCrudRepository我想在 a 中使用的,RestController但 Spring 没有发现它再被注入。在我将存储库重构为响应式CrudRepository之前(它是之前的),存储库是由 Spring 找到并注入的。

现在我收到这个错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in de.shinythings.microservices.core.product.services.ProductServiceImpl required a bean of type 'de.shinythings.microservices.core.product.persistence.ProductRepository' that could not be found.


Action:

Consider defining a bean of type 'de.shinythings.microservices.core.product.persistence.ProductRepository' in your configuration.
Run Code Online (Sandbox Code Playgroud)

存储库如下所示: 链接到 GitHub

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in de.shinythings.microservices.core.product.services.ProductServiceImpl required a bean of type 'de.shinythings.microservices.core.product.persistence.ProductRepository' that could not be found.


Action:

Consider defining …
Run Code Online (Sandbox Code Playgroud)

spring dependency-injection reactive-programming kotlin spring-boot

3
推荐指数
1
解决办法
890
查看次数

Ballerina 中的线程和响应式编程

我刚刚通过阅读https://ballerina.io/文档开始关注芭蕾舞女演员。当我尝试运行 Hello World Parallel 时,我不知道它在内部是如何工作的?

 import ballerina/io;
    public function main() {
        @strand {thread: "any"}
        worker w1 {
            io:println("Hello, World! #m");
        }
    
        @strand {thread: "any"}
        worker w2 {
            io:println("Hello, World! #n");
        }
        @strand {thread: "any"}
        worker w3 {
            io:println("Hello, World! #k");
        }
    }
Run Code Online (Sandbox Code Playgroud)
  1. 当我运行此代码时,有多少线程在 4 个或少于 4 个的后面运行?
  2. 线程在java中是非常昂贵的,当我们创建一个线程的同时,JVM会创建OS级线程,会消耗大量内存。芭蕾舞演员是否也遵循相同的方式(Native Thread Model)?
  3. 我们可以在芭蕾舞演员中使用轻质线吗?就像 Project Loom(fibers) 将要介绍的那样
  4. 芭蕾舞演员是否完全支持反应式编程?
  5. 芭蕾舞演员有没有提供包连接MongoDB、Redis、Cassandra 不阻塞?我的意思是反应方式

asynchronous wso2 reactive-programming ballerina

3
推荐指数
1
解决办法
109
查看次数

异步编程和反应式编程

这个问题在我脑海里盘旋了一年左右。实际上,异步和非阻塞有什么区别。当我们在代码中调用阻塞部分时,它就会变成阻塞,这是同步的,同时它不会是非阻塞的。

如果我们在主线程之外创建另一个线程来进行异步编程并且我们必须返回一些值所以我们必须join()在java中定义方法并且join()阻塞操作那么它实际上是异步的吗?

我需要知道以下问题的答案

  1. 如果阻塞类似于同步,那么异步和非阻塞之间有什么区别。它应该是相似的吗?如果不是那么为什么?

  2. 非阻塞的响应式编程是否完全异步编程?

java asynchronous reactive-programming

3
推荐指数
1
解决办法
2362
查看次数