Skip to content

Instantly share code, notes, and snippets.

View gauravat16's full-sized avatar
💭
working

Gaurav Sharma gauravat16

💭
working
View GitHub Profile
@gauravat16
gauravat16 / UsernameController.java
Created July 9, 2020 12:21
API for username validation
package gaurav.examples.redis.bloomfilter.controller;
import gaurav.examples.redis.bloomfilter.service.UserNameValidatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
package gaurav.examples.redis.bloomfilter.service.impl;
import gaurav.examples.redis.bloomfilter.service.BloomFilterService;
import gaurav.examples.redis.bloomfilter.service.UserNameValidatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserNameValidatorServiceImpl implements UserNameValidatorService {
@gauravat16
gauravat16 / BloomFilterServiceImpl.java
Created July 9, 2020 12:20
Redisson bloom filter service and data setup
package gaurav.examples.redis.bloomfilter.service.impl;
import gaurav.examples.redis.bloomfilter.service.BloomFilterService;
import lombok.Synchronized;
import lombok.extern.log4j.Log4j2;
import org.ajbrown.namemachine.NameGenerator;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
@gauravat16
gauravat16 / BeanConfig.java
Created July 9, 2020 12:12
Redisson Beans
package gaurav.examples.redis.bloomfilter.config;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@gauravat16
gauravat16 / application.properties
Created July 9, 2020 12:09
properties for redisson
spring.application.name=Redis-BloomFilter
server.servlet.context-path=/rBloom
server.port=8080
redisson.redisUrl=redis://127.0.0.1:6379
@gauravat16
gauravat16 / RedissonConfig.java
Created July 9, 2020 12:09
Redisson Config File
package gaurav.examples.redis.bloomfilter.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties("redisson")
@Data
public class RedissonConfig {
@gauravat16
gauravat16 / build.gradle
Created July 9, 2020 12:06
Gradle file for RBloom
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'gaurav.examples'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
public class GatewayServer extends Server {
private double ratio;
private PaymentGateway gateway;
public GatewayServer(String host, int port, double ratio, PaymentGateway gateway) {
super(host, port);
this.ratio = ratio;
this.gateway = gateway;
}
@Service
public class GatewayUtilServiceImpl implements GatewayUtilService {
@Autowired
private LoadBalancerClient loadBalancer;
@Override
public PaymentGateway getPaymentGateway() {
ServiceInstance instance = loadBalancer.choose("payment-gateway");
@Configuration
@RibbonClient(name = "payment-gateway", configuration = PaymentGatewayConfiguration.class)
public class PaymentGatewayConfiguration {
@Bean
public IPing ribbonPing(IClientConfig config) {
return new PingUrl();
}
@Bean