Skip to content

Instantly share code, notes, and snippets.

View bijukunjummen's full-sized avatar

Biju Kunjummen bijukunjummen

View GitHub Profile
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public interface PubSubService {
Mono<Void> publish(Message message);
}
public Mono<ChatRoom> getById(String id) {
return Mono.defer(() -> {
ApiFuture<DocumentSnapshot> chatRoomSnapshotFuture =
firestore.collection(ServiceConstants.CHAT_ROOMS).document(id).get();
Mono<DocumentSnapshot> chatRoomSnapshotMono = ApiFutureUtil.toMono(chatRoomSnapshotFuture);
return chatRoomSnapshotMono.map(chatRoomSnapshot ->
new ChatRoom(chatRoomSnapshot.getId(), chatRoomSnapshot.getString("name")));
});
}
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutureCallback;
import com.google.api.core.ApiFutures;
import reactor.core.publisher.Mono;
public class ApiFutureUtil {
public static <T> Mono<T> toMono(ApiFuture<T> apiFuture) {
return Mono.create(sink -> {
ApiFutureCallback<T> callback = new ApiFutureCallback<T>() {
@Override
public Mono<ChatRoom> getById(String id) {
ApiFuture<DocumentSnapshot> chatRoomSnapshotFuture =
firestore.collection(ServiceConstants.CHAT_ROOMS).document(id).get();
Mono<DocumentSnapshot> chatRoomSnapshotMono = ApiFutureUtil.toMono(chatRoomSnapshotFuture);
return chatRoomSnapshotMono.map(chatRoomSnapshot ->
new ChatRoom(chatRoomSnapshot.getId(), chatRoomSnapshot.getString("name")));
}
public ChatRoom getById(String id) {
ApiFuture<DocumentSnapshot> chatRoomSnapshotFuture =
firestore.collection(ServiceConstants.CHAT_ROOMS).document(id).get();
try {
DocumentSnapshot chatRoomSnapshot = chatRoomSnapshotFuture.get();
return new ChatRoom(chatRoomSnapshot.getId(), chatRoomSnapshot.getString("name"));
} catch (Exception e) {
throw new RuntimeException("Could not retrieve by id", e);
}
}
gcloud compute instances create europe-north1-a-instance \
--zone=europe-north1-a --machine-type=e2-micro \
--create-disk=image=projects/debian-cloud/global/images/debian-10-buster-v20211209,mode=rw
gcloud compute ssh europe-north1-a-instance --zone=europe-north1-a
curl 'http://ANYCAST_OP/caller/messages' \
-H 'Content-Type: application/json' \
-H 'Accept: */*' \
gcloud compute instances create us-west1-a-instance \
--zone=us-west1-a --machine-type=e2-micro \
--create-disk=image=projects/debian-cloud/global/images/debian-10-buster-v20211209,mode=rw
gcloud compute ssh us-west1-a-instance --zone=us-west1-a
## From the instance..
curl 'http://ANYCAST_IP/caller/messages' \
-H 'Content-Type: application/json' \
-H 'Accept: */*' \
apiVersion: networking.gke.io/v1
kind: MultiClusterService
metadata:
name: sample-caller-mcs
namespace: istio-apps
spec:
template:
spec:
selector:
app: sample-caller
apiVersion: networking.gke.io/v1
kind: MultiClusterIngress
metadata:
name: sample-caller-ingress
namespace: istio-apps
spec:
template:
spec:
backend:
serviceName: sample-caller-mcs
const { run_v1, google } = require('googleapis');
const { ProjectsClient } = require('@google-cloud/resource-manager');
exports.scanAndDeletePreviewServices = async (message, context) => {
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform']
})
const defaultOptions = {
rootUrl: 'https://us-central1-run.googleapis.com'
}