Spring boot graphql-java and subscriptions - graphql

The following example https://github.com/graphql-java/graphql-java-subscription-example which use's graphql-java for subscriptions over a websocket.
How can the same idea be done within the spring version? GraphQLSubscriptionResolver needs to return a publisher but I am unable to work out how this can then be used with a web socket.
The example above seems fine within a none spring version.

A good friend of mine has made an example in his github repository.
The code is not the nicest (because it was for our own personal needs) but it is a nice example
Have fun

Here's a port of the graphql-java example using GraphQL-SPQR with Spring Boot. I'll soon merge it into the GraphQL-SPQR samples project.
Same as with the other answer, while it uses GraphQL-SPQR to generate the schema, the Spring and websockets bit is the same as you'd have with graphql-java directly.
There's now a new and somewhat more realistic example using GraphQL SPQR Spring Boot Starter. It publishes updates when a relevant mutation runs.

I just published a workshop in which you can learn how to implement the subscription operations.
http://graphql-java.wesovilabs.com
Let me know If you have any doubt
I hope you find it useful!
Thanks

Related

Spring Boot Microservices Saga example

I am looking to learn the Spring Boot Microservices Saga based project. I went through web and found many theoretical links like https://www.baeldung.com/cs/saga-pattern-microservices and https://microservices.io/patterns/data/saga.html, but I don't find the simple source code witch depicts the working code.
Can anyone please share the link to source code which is working POC?
You can try the following if it helps:
https://github.com/berndruecker/trip-booking-saga-java
Although I would suggest you using the Axon framework. It is designed for an event-driven system. You can easily find many examples related to the saga in axon as well. May be something like this: https://github.com/dashsaurabh/saga-pattern-axon-spring-boot-sample

Need and example using panache Reactive JPA

I found the quarkus-hibernate-reactive-panache extension but I couldn't find an example of it using Panache orm with reactive repositories (In my case I use postgresql).
PanacheRepositoryBase.java seems that works as I need (smallrye.mutiny.*), could anybody link me to an example?
Thanks in advace, and nice work on quarkus project.
Regards
UPDATE: A quickstart is now available on the Quarkus quickstarts development branch: https://github.com/quarkusio/quarkus-quickstarts/tree/development/hibernate-reactive-panache-quickstart
Old answer:
I've just created a new quickstart for Hibernate Reactive with Panache in Quarkus:
https://github.com/quarkusio/quarkus-quickstarts/pull/809
Hopefully, it will be included soon in the list of quickstarts, but you can have a look already if you want to play with it.

Which graphql-spring-boot-starter should I choose?

I'm thinking about adding GraphQL functionalities to my Spring Boot application.
I found there are two artifacts for that.
One is com.graphql-java-kickstart:graphql-spring-boot-starter and the other is com.graphql-java:graphql-spring-boot-starter.
Which one should I choose?
These are different Starters (by different teams) providing different features, so there's no right or wrong answer. Here's a quick overview of what I'm aware is available:
The original starter made by the graphql-java team (com.graphql-java:graphql-spring-boot-starter) is now, I believe, defunct and superseded by the Spring GraphQL.
Spring GraphQL (org.springframework.boot:spring-boot-starter-web or org.springframework.boot:spring-boot-starter-webflux) is intended for schema-first development, is relatively simple and not very feature rich, but it's easy to use and works well with other Spring projects (like e.g. WebFlux and Spring Security).
If you want to go code-first (which I argue is still schema-first, just better), use graphql-spqr-spring-boot-starter, which will generate the GraphQL schema and an end-point for you, with no extra code needed. It's quickest way possible to expose Spring services. There's a sample project here. I'm the main author of that project, so this is a shameless plug, but I honestly believe it's lightyears ahead of other projects in terms of usability. The next version will be based on Spring GraphQL, so it should inherit most/all benefits as well (like e.g. RSocket support, which it currently lacks).
There's also DGS by Netflix (com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter). It is also schema-first, has a plenty of features, but is also highly opinionated. I have no first-hand experience with it, but it is well documented, so you should have no problems finding what you need about it.
If you're already using graphql-java-tools (maintained by the Kickstart team), you'll likely want to go for com.graphql-java-kickstart:graphql-spring-boot-starter as they're intended to be used together. I have no clue how actively this project is maintained these days.

Spring Statemachine persister for spring data

We are currently investigating spring state machine and we have a very similar need to the eventservice sample with a pool and context switching using a repository, the only problem is redis is linux only (for production) and we can not lean on that... is there a clean out-of-the-box way to integrate persistence using spring data or will i have to write my own implementation for StateMachinePersister.
https://github.com/spring-projects/spring-statemachine/tree/master/spring-statemachine-samples/eventservice/src/main/java/demo/eventservice
should i go about using AbstractStateMachinePersister or StateMachinePersist?
thanks!
There is no OOB spring data integration so you need to use low level API's to build your own persist impl. Having said that, spring data support has been in my mind but just haven't had time to push it forward. PR's highly appreciated ;)
StateMachinePersister is an interface to follow which AbstractStateMachinePersister implements.

Which should I use mail outbound-channel-adapter or org.springframework.mail.MailSender [duplicate]

I have too many emails. I should write scheduler in order to send messages to them. Messages are different. I use spring framework 4.x.
I can write simple class, which connects to SMTP server. But in this case I should write my thread library too in order to send emails parallel.
Do spring have already written library which give me more flexible way to do this tasks? I do not want to use threads. It will be nice if spring already have this functionality.
Do I need Spring integration for this?
Best regards,
Yes, you definitely can do that with Spring Integration, because there is an ExecutorChannel implementation with can be supplied with an TaskExecutor from the Spring Core:
<channel id="sendEmailChannel">
<dispatcher task-executor="threadPoolTaskExecutor"/>
</channel>
<int-mail:outbound-channel-adapter channel="sendEmailChannel" mail-sender="mailSender"/>
But anyway you should keep in mind that all Spring Integration components are based on the Java and that ExecutorService is used on the background.
From other side if you need only the mail sending stuff from the Spring Integration, it would be an overhead and can simply use Core Spring Framework legacy like JavaMailSender as a bean and #Async for the sendMail method to achieve your parallel requirement.
UPDATE
could you tell me whether I need JMS for this situation?
I don't see any JMS-related stuff here. You don't have (or at least don't show) any real integration points in your solution. The same I can say even about Spring Integration just for email sending. However with the Spring Boot your SI config will be enough short. From other side if you'll study Spring Integration better eventually you'll get more gain to rely on the Integration components for your systems, as internally, as well as externally with other systems through JMS, AMQP, Kafka etc.
To be honest: a lot of years ago my first acquaintance with Spring Integration was due the requirement to get files from the FTP and have ability to pick up new files automatically. I found the solution only in the Spring Integration 1.0.0.M1. After that short XML config for the <int-ftp:inbound-channel-adapter> I loved Spring Integration and since that time it became as a part of my life. :-)
So, it's up to you to go ahead with Spring Integration in your simple app, or just follow with more formal solution with JavaMailSender direct usage.
You should use java executors framework. For example you can write something like the code below:
ExecutorService executor = Executors.newWorkStealingPool();
executor.execute(() -> mailSender.send(mail));

Resources