Skip to content

Instantly share code, notes, and snippets.

@stefanotroia
stefanotroia / bookServiceCache.java
Last active December 11, 2019 07:52
Book service with caching
@Service
@Slf4j
public class BookService extends BaseService<Book> {
private BookRepository repository;
@Autowired
public BookService(BookRepository repository) {
this.repository = repository;
}
@stefanotroia
stefanotroia / baseService.java
Created December 11, 2019 07:43
base service with caching
@Service
@Slf4j
public class BaseService<E extends GenericEntity> {
@Autowired
protected HazlecastService hazlecastService;
public Mono<E> findCacheValue(String cacheName, List<String> keys, Mono<E> fallBackMono) {
return CacheMono
@stefanotroia
stefanotroia / hazelcastService.java
Created December 11, 2019 07:32
HazelCast service
@Service
@Slf4j
public class HazelcastService {
@Getter
private HazelcastInstance hzInstance;
@PostConstruct
private void init() {
@stefanotroia
stefanotroia / spring-cache-hazelcast-pom.xml
Created December 11, 2019 07:27
Spring webflux caching with Hazelcast pom
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
@stefanotroia
stefanotroia / firebase-pom.xml
Created November 26, 2019 07:05
Firebase notification pom
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.11.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
@stefanotroia
stefanotroia / firebase-notification-service.java
Created November 26, 2019 06:58
Firebase Notification Service
@Service
@Slf4j
public class NotificationService {
@Autowired
private Config config;
private EmitterProcessor<Notification> emitterSource = EmitterProcessor.create();
private Flux<Notification> fluxNotification = emitterSource.publish().autoConnect();
@PostConstruct
@stefanotroia
stefanotroia / firebase.yml
Created November 25, 2019 15:22
Fireabse configuration example
firebase:
pkey: '{
"type": "",
"project_id": "",
"private_key_id": ""
"private_key": "",
"client_email": "",
"client_id": "",
"auth_uri": "",
"token_uri": "",
public class BaseController<E extends BaseEntity> {
@Autowired
private BaseService<E> baseService;
@PostMapping("/save")
public Mono<E> save(Authentication auth,
@RequestBody E entity) {
return baseService.save(getTenant(auth),entity);
}
@stefanotroia
stefanotroia / base-service.java
Created November 19, 2019 20:14
Base service with generics
@Service
@Slf4j
public class BaseService<E extends BaseEntity> {
@Autowired
protected GenericRepository<E> generalRepo;
public Mono<E> findEnitity(String entityId, String tenantId) {
return generalRepo.findFirstByIdAndTenantId(entityId,tenantId);
}
@stefanotroia
stefanotroia / generic-repository.java
Last active November 19, 2019 20:15
Generic Repository
@Repository
public interface GenericRepository<E extends BaseEntity> extends ReactiveCrudRepository<E, String> {
Mono<Void> deleteByIdAndTenantId(String id, String tenantId);
Mono<E> findFirstByIdAndTenantId(String id, String tenantId);
}