Skip to content

Commit

Permalink
Take AMQP_URL as an env var.
Browse files Browse the repository at this point in the history
  • Loading branch information
chmac committed Nov 23, 2024
1 parent d0dc1dc commit 7e31acd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion nr-server/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ await new cliffy.Command()
"SUBSCRIBE=<subscribe:boolean>",
"Subscribe to relays to fetch events instead of using AMQP."
)
.env(
"AMQP_URL=<amqpUrl:string>",
"The URL to connect to AMQP, like amqp://insecure:insecure@localhost:5672"
)
.action((options) => {
const { isDev } = options;
const privateKey = getOrCreatePrivateKey(options.privateKeyNsec);
Expand All @@ -42,7 +46,7 @@ await new cliffy.Command()
if (options.subscribe) {
subscribeAndRepost(privateKey, isDev, maxAgeMinutes);
} else {
consume(privateKey, isDev);
consume(privateKey, isDev, options.amqpUrl);
}
})
.parse(Deno.args);
15 changes: 11 additions & 4 deletions nr-server/src/consume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ import { processEventFactoryFactory } from "./validation/repost.ts";
const exchangeName = "nostrEvents";
const queueName = "repost";

export async function consume(privateKey: Uint8Array, isDev: true | undefined) {
export async function consume(
privateKey: Uint8Array,
isDev: true | undefined,
amqpUrl?: string
) {
const relayPool = await getRelayPool(isDev);
const processEventFactory = processEventFactoryFactory(relayPool, privateKey);

const connection = await amqp.connect(
"amqp://insecure:insecure@localhost:5672"
);
const amqpUrlActual =
typeof amqpUrl === "string" && amqpUrl.length > 0
? amqpUrl
: "amqp://insecure:insecure@localhost:5672";

const connection = await amqp.connect(amqpUrlActual);
const channel = await connection.openChannel();
await channel.declareExchange({
exchange: exchangeName,
Expand Down

0 comments on commit 7e31acd

Please sign in to comment.