This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.zup.edu.pix.registra | |
import io.micronaut.core.annotation.AnnotationValue | |
import io.micronaut.validation.validator.constraints.ConstraintValidator | |
import io.micronaut.validation.validator.constraints.ConstraintValidatorContext | |
import javax.inject.Singleton | |
import javax.validation.Constraint | |
import javax.validation.Payload | |
import kotlin.annotation.AnnotationRetention.RUNTIME | |
import kotlin.annotation.AnnotationTarget.CLASS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HowToUse { | |
public static void main(String[] args) { | |
MercadoLivreHttpClient client = new MercadoLivreHttpClient(); | |
MercadoLivreHttpClient securedClient = new MercadoLivreSecuredHttpClient(client); | |
HttpResponse<?> response = securedClient.post(null); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
open class CreateProposalEndpoint(@Inject val repository: ProposalRespository) : ProposalGrpcServiceGrpc.ProposalGrpcServiceImplBase() { | |
@Transactional // starts the current transaction | |
open override fun create(request: CreateProposalRequest, responseObserver: StreamObserver<CreateProposalResponse>) { | |
val proposal = repository.save(request.toModel()) // with Hibernate, the INSERT may not be flushed here | |
// returns to the client without waiting for the commit | |
responseObserver.onNext(CreateProposalResponse.newBuilder().build()) |
At a high-level, we need to understand two points:
- gRPC is built on HTTP/2, and HTTP/2 is designed to have a single long-lived TCP connection (a sticky and persistent connection);
- To do gRPC load balancing, we need to shift from connection balancing to request balancing;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class BeanValidationConfig { | |
/** | |
* The idea here is to configure Hibernate to use the same ValidatorFactory used by Spring, | |
* so that Hibernate will be able to handle custom validations that need to use dependency injection (DI) | |
*/ | |
@Bean | |
public HibernatePropertiesCustomizer hibernatePropertiesCustomizer(final Validator validator) { | |
return new HibernatePropertiesCustomizer() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.zup.edu.shared.grpc | |
import io.grpc.BindableService | |
import io.grpc.stub.StreamObserver | |
import io.micronaut.aop.MethodInterceptor | |
import io.micronaut.aop.MethodInvocationContext | |
import org.slf4j.LoggerFactory | |
import javax.inject.Inject | |
import javax.inject.Singleton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.zup.edu.shared.grpc | |
import io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener | |
import io.grpc.Metadata | |
import io.grpc.ServerCall | |
import io.grpc.ServerCallHandler | |
import io.grpc.ServerInterceptor | |
import org.slf4j.LoggerFactory | |
import javax.inject.Inject | |
import javax.inject.Singleton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.zup.edu.nossocartao.propostas.shared.web; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Component; | |
import org.springframework.web.context.annotation.RequestScope; | |
import javax.servlet.http.HttpServletRequest; | |
import java.util.Objects; | |
import java.util.stream.Stream; | |
@Component |