Spring Flashcards

1
Q

WebFlux

A

Spring WebFlux is a web framework that is built on top of Project Reactor, to give you asynchronous I/O, and allow your application to perform better.
Reactive web programming is great for applications that have streaming data, and clients that consume it and stream it to their users. It is not great for developing CRUD apps. If you want to develop a CRUD API, stick with Spring MVC and be happy about it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the benefits of Spring Webflux?

A

Spring MVC is a web framework based on the Servlet API; such apps can be deployed on Servlet containers (like Jetty, Tomcat, Undertow).
Spring WebFlux is a reactive web framework based on a reactive HTTP layer; such apps can be deployed on Netty or Undertow (with native adapters) or Jetty/Tomcat/any Servlet 3.1 container (thanks to a Servlet 3.1 adapter).
Spring Boot applications can use Spring MVC or Spring WebFlux.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Reactive Programming in Spring Webflux?

A

Reactive programming is a programming paradigm that promotes an asynchronous, non-blocking, event-driven approach to data processing. Reactive programming involves modeling data and events as observable data streams and implementing data processing routines to react to the changes in those streams.
Before digging deeper into reactive world, first understand the difference between blocking vs non-blocking request processing.One important thing to remember is back pressure. In non-blocking code, it becomes important to control the rate of events so that a fast producer does not overwhelm its destination.
Reactive web programming is great for applications that have streaming data, and clients that consume it and stream it to their users.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the main components of Spring Webflux?

A

The main components of Spring Webflux are the RouterFunction and the HandlerFunction. The RouterFunction is responsible for mapping incoming requests to the appropriate HandlerFunction. The HandlerFunction is responsible for handling the request and returning a response.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In which situations would I want to use reactive programming over traditional techniques like multithreading and promises?

A

Reactive programming can provide benefits over traditional techniques in situations where you need to process a large number of small requests quickly, or where you need to be able to handle a variable number of requests. Additionally, reactive programming can make it easier to reason about your code, since you can think about it in terms of data flows instead of individual threads of execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are hot publishers and cold publishers?

A

A hot publisher is a publisher that emits data even if there is no Subscriber subscribed to it. A cold publisher is a publisher that only emits data when there is at least one Subscriber subscribed to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is bodyToMono?

A

Use bodyToMono for retrieving a single item, it emits 0-1 items.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is bodyToFlux?

A

it is used to to retrieve a collection resource of type Flux from endpoint

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Autowiring Dependencies

A

Wiring allows the Spring container to automatically resolve dependencies between collaborating beans by inspecting the beans that have been defined.

There are four modes of autowiring a bean using an XML configuration:
no: the default value – this means no autowiring is used for the bean and we have to explicitly name the dependencies.

byName: autowiring is done based on the name of the property, therefore Spring will look for a bean with the same name as the property that needs to be set.

byType: similar to the byName autowiring, only based on the type of the property. This means Spring will look for a bean with the same type of the property to set. If there’s more than one bean of that type, the framework throws an exception.

constructor: autowiring is done based on constructor arguments, meaning Spring will look for beans with the same type as the constructor arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly