Code Monkey home page Code Monkey logo

Comments (4)

timcharper avatar timcharper commented on August 22, 2024

Hi @slevine - this is certainly possible. But, can you help me understand a little more about your use case? Why do you feel like this is important?

The Publisher class is not declared as final, so you could extend it that way.

class DeclaringPublisher(routingKey: String, topicBinding: TopicBinding) extends Publisher(topicBinding.exchange.exchangeName, routingKey) {
  private var declared: Boolean = false
  override def apply(c: Channel, data: Array[Byte], properties: BasicProperties): Unit = {
    if (! declared) synchronized {
      if ( ! declared ) {
        topicBinding.declare(c)
        declared = true
      }
    }
    super.apply(c, data, properties)
  }
}

Then:

val declaringPublisher = DeclaringPublisher("my.topic", TopicBinding(...))
Message(declaringPublisher, data)

Another option, if you want to just declare the topic, but not send a message:

class EagerDeclare(definition: QueueDefinition) extends MessageForPublicationLike {
  private val _declared: Promise[Unit]
  val declared = _applied.future
  def apply(c: Channel): Unit =
    _declared.complete(Try(definition.declare(c)))
}

val declaration = EagerDeclare(TopicBinding(...))
rabbitControl ! declaration
declaration.declared.foreach { _ =>
  // ready for action
}

Both of these are kind of hacks, granted. If I can learn more about what your problem is, we can come up with a better solution and perhaps get it implemented before the RC label comes off.

from op-rabbit.

slevine avatar slevine commented on August 22, 2024

Thanks for the quick reply @timcharper -- really appreciate it. The main reason it is important to us is because we are not using standard exchange types, and some of the time, the producer will bind before the consumer, so we needed a mechanism to change the ex type when the producer binds.

from op-rabbit.

timcharper avatar timcharper commented on August 22, 2024

Okay, the obvious solution here would be to allow you to pass a QueueDefinition or an ExchangeDefinition to your message publisher, and having said definition lazily apply.

Do you think that will solve it well enough, or can you think of a more enlightened way to solve it?

from op-rabbit.

timcharper avatar timcharper commented on August 22, 2024

@slevine please see v1.0.0-RC4, which should support the case you need. There was an already implemented feature that was somewhat similar to it, so I made the solution more general to apply to yours, also.

From The Upgrading Wiki Page:

val factory = Message.factory(
  Publisher.queue(
    Queue("ahora-existe")))

val factory = Message.factory(
  Publisher.exchange(
    Binding.topic(
      Queue("ahora-existe", topics = List("los.nachos.*")))))

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.