Code Monkey home page Code Monkey logo

Comments (6)

timcharper avatar timcharper commented on August 22, 2024

I'll look into this this evening.

from op-rabbit.

timcharper avatar timcharper commented on August 22, 2024
  1. That solution only works when publishing messages directly to the queue. I fear that having op-rabbit handle such a thing would explode the complexity. I think providing a way to specify that requirement is a better idea.

  2. The ack is coming from RabbitMQ itself. See https://www.rabbitmq.com/confirms.html

We can publish the message in mandatory mode, but unfortunately, that causes the message to be routed back to us without the delivery tag, and unless if set the delivery tag in a custom header for every outbound message, I don't see any way to NACK a message that did not get delivered. It does highlight a bigger issue, however. Perhaps the best way to do it would be to have the application allocate a confirmedPublisher per sink, have it publish in mandatory mode, and then have the whole sink fail if a message is unrouteable.

from op-rabbit.

timcharper avatar timcharper commented on August 22, 2024

I've been thinking about this... I just switched the publisher strategy from a function that receives a channel, payload, etc. and returns unit. Since a publisher strategy can be bound to a specific queue, you could have it verify the existence of the queue to which it's publishing, and then fail if it doesn't exist.

class VerifyingQueuePublisher(queue: String) extends MessagePublisher {
  private var queueVerified = false
  def apply(c: Channel, data: Array[Byte], properties: BasicProperties): Unit = {
    if (!queueVerified) {
      c.queueDeclarePassive(queueName)
      queueVerified = true
    }
    c.basicPublish("", queue, properties, data)
  }
}

// returns failed Future if target queue does not exist:
rabbitControl ? ConfirmedMessage(VerifyingQueuePublisher(queueName), data)

What do you think of this? Would this solve your problem?

from op-rabbit.

 avatar commented on August 22, 2024

Yeah, that looks pretty good. I was going to suggest adding another function to MessagePublisher that gets called when the stream is materialized, but this might be better as it keeps the interface simple. The only drawback I can see, is that in order to verify the queue exists, it means making the publisher mutable.

About the confirmations, I have no idea how I didn't notice it before, but that's really bad. What's the point of sending an ack if the message wasn't persisted (or, at least, not where the sender intended it to be)?
Anyway, I'm not so sure about the mandatory mode, it seems like a lot of overhead without necessarily solving the problem.

from op-rabbit.

timcharper avatar timcharper commented on August 22, 2024

Okay, great. Thanks for the feedback. I'll work towards making this a reality (what's lacking is proper error handling in the publisher strategy, and channeling that exception back from the ConfirmedPublisher) And... it's not mutable... it's "memoized / lazy"! :D

I'm also going to work on simplifying the definition of implementing custom consumer patterns, providing "escape" hatches where you can leave the opinionated / safety of op-rabbit when needed.

from op-rabbit.

timcharper avatar timcharper commented on August 22, 2024

Supported; 6b743ba

from op-rabbit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.