Skip to content

Commit

Permalink
use third party libraries to allow aurionchat compatibility mode
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Dec 28, 2024
1 parent bed2eb3 commit b66b5b4
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/main/java/org/comroid/api/net/Rabbit.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package org.comroid.api.net;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Delivery;
import lombok.Builder;
import lombok.SneakyThrows;
import lombok.Value;
import lombok.experimental.NonFinal;
import lombok.extern.java.Log;
import org.comroid.api.ByteConverter;
import org.comroid.api.Polyfill;
import org.comroid.api.data.seri.DataNode;
import org.comroid.api.data.seri.adp.JSON;
import org.comroid.api.func.exc.ThrowingFunction;
import org.comroid.api.func.ext.Wrap;
import org.comroid.api.func.util.Debug;
import org.comroid.api.func.util.Event;
Expand All @@ -26,7 +22,6 @@
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

import static java.util.Collections.*;
import static org.comroid.api.Polyfill.*;
Expand All @@ -40,14 +35,15 @@ public class Rabbit {

public static Wrap<Rabbit> of(@Nullable String uri) {
if (uri == null) return Wrap.empty();
final var uri0 = Polyfill.uri(uri);
final var uri0 = uri(uri);
return SoftDepend.type("com.rabbitmq.client.Connection")
.map($ -> $cache.computeIfAbsent(uri0, Rabbit::new));
}

URI uri;
Map<String, Exchange> exchanges = new ConcurrentHashMap<>();
@NonFinal Connection connection;

private Rabbit(URI uri) {
this.uri = uri;
this.connection = touch();
Expand All @@ -65,24 +61,29 @@ private synchronized Connection touch() {
return factory.newConnection();
}

@lombok.Builder(builderMethodName = "bind", buildMethodName = "create", builderClassName = "Binder")
public <T> Exchange.Route<T> bind(String exchange, String routingKey, ByteConverter<T> converter) {
return exchange(exchange).route(routingKey, converter);
@Builder(builderMethodName = "bind", buildMethodName = "create", builderClassName = "Binder")
public <T> Exchange.Route<T> bind(String exchange, @Nullable String exchangeType, String routingKey, ByteConverter<T> converter) {
return exchange(exchange, exchangeType).route(routingKey, converter);
}

public Exchange exchange(String exchange) {
return exchanges.computeIfAbsent(exchange, Exchange::new);
return exchange(exchange, null);
}

public Exchange exchange(String exchange, String exchangeType) {
return exchanges.computeIfAbsent(exchange, exc -> new Exchange(exc, exchangeType));
}

@Value
public class Exchange {
Map<String, Route<?>> routes = new ConcurrentHashMap<>();
String exchange;
String exchangeType;
@NonFinal Channel channel;

@SneakyThrows
private Exchange(String exchange) {
this.exchange = exchange;
private Exchange(String exchange, @Nullable String exchangeType) {
this.exchange = exchange;
this.exchangeType = exchangeType == null ? "topic" : exchangeType;
}

@SneakyThrows
Expand All @@ -97,7 +98,7 @@ private synchronized Channel touch() {
}
connection = Rabbit.this.touch();
channel = connection.createChannel();
channel.exchangeDeclare(exchange, "topic");
channel.exchangeDeclare(exchange, exchangeType);
return channel;
}

Expand Down

0 comments on commit b66b5b4

Please sign in to comment.