π―
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
import asyncio_redis | |
import asyncio | |
channels = ['channel1', 'weather'] | |
async def start(): | |
connection = await asyncio_redis.Connection.create(host='127.0.0.1', port=6379) | |
subscriber = await connection.start_subscribe() | |
await subscriber.subscribe(channels) |
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
// Example SSE server in Golang. | |
// $ go run sse.go | |
// Inspired from https://gist.github.com/ismasan/3fb75381cd2deb6bfa9c | |
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" |
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
@Aspect | |
@Slf4j | |
public class LoggerAspect { | |
@Around("@annotation(Loggable)") | |
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { | |
long start = System.currentTimeMillis(); | |
var result = joinPoint.proceed(); |
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 abstract class AbstractWebClient { | |
private static final String MIME_TYPE = "application/json"; | |
private final WebClient webClient; | |
public AbstractWebClient(String clientUrl) { | |
this.webClient = WebClient.builder() | |
.baseUrl(clientUrl) | |
.defaultHeader(HttpHeaders.CONTENT_TYPE, MIME_TYPE) | |
.build(); |
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
@Component | |
@Slf4j | |
public class TraceIdFilter implements WebFilter { | |
@Override | |
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { | |
Map<String, String> headers = exchange.getRequest().getHeaders().toSingleValueMap(); | |
return chain.filter(exchange) | |
.subscriberContext(context -> { |
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
@Component | |
@Slf4j | |
public class TraceIdFilter implements WebFilter { | |
@Override | |
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { | |
Map<String, String> headers = exchange.getRequest().getHeaders().toSingleValueMap(); | |
var traceId = ""; | |
if (headers.containsKey("X-B3-TRACEID")) { |
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
class SingletonMeta(type): | |
_instance = None | |
def __call__(self): | |
if self._instance is None: | |
self._instance = super().__call__() | |
return self._instance |
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
import msgpack | |
class Btypes: | |
def pack(self): | |
return msgpack.packb(Btypes.get_all_vars(self)) | |
@classmethod | |
def unpack(cls, d): | |
return cls(**msgpack.unpackb(d, raw=False)) |
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
from app.serializers.serialization_types import Btypes | |
class OrderStatus: | |
INITIATED = 0 | |
PACKING = 1 | |
SHIPPED = 2 | |
DELIVERED = 3 | |
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
from ..serialization_types import Etypes, type_check | |
from .serializer import CreateOrderReq | |
class OrderOperations: | |
CREATE_ORDER = 'create_order' | |
GET_ORDER = 'get_order' | |
class CreateOrder(Etypes): |
OlderNewer