3 Replies Latest reply on Feb 3, 2007 8:50 PM by Alexander Torstling

    Joining messages (queues)

    Alexander Torstling Newbie

      Hi!

      I have the following use case:

      *Wait for a free resource
      *When resource is free, wait for next job, then use resource to process job.

      So, i need to wait until there is BOTH a resource and a job available. All resources are equal, so I can use any resource with any job.

      What's the best way of accomplishing this?

      My current (flawed?) implementation is as follows:

      I'm putting the resources in one queue as they become available, and then I have an MDB registered for that queue (P2P).

      The job queue is a separate queue, and jobs are added to the queue as soon as a request arrives (might be days or months between jobs, then suddenly I could get a large amount at once).

      When a resource is ready, the onMessage()-method of my MDB is called.
      In this method, I then create a MessageConsumer for the job-queue, and call receive() with infinite timeout. This seems to be a sub-optimal solution, since i'm blocking the MDB thread and Jboss AS seems to dislike my approach (refuses to shutdown while thread is blocked) ;)

      I've also tried another solution, where I have a n second timeout on the receive method, and call ctx.setRollbackOnly() if no job is available when a resource is free.

      This makes JBoss assume that the operation failed non-intentionally and puts all my messages in the dead-letter-queue after 10 retries. I could increase the max amount of retries, but it feels like I'm going down the wrong road here... Is there a nicer way of joining messages?

      I basically have free hands when it comes to this, so any suggestion is more than welcomed!

      Best regards

      Alex

        • 1. Re: Joining messages (queues)
          Alexander Torstling Newbie

          Anyone?

          I'll try to be more clear:

          *How do I wait for messages from more than one queue before starting processing?

          • 2. Re: Joining messages (queues)
            byorn de silva Newbie

            How does the MDB know the resouce is ready ???
            You could use a scheduled task to execute every 5 seconds (n minutes) to check the resource.

            • 3. Re: Joining messages (queues)
              Alexander Torstling Newbie

               

              "Byorn" wrote:
              How does the MDB know the resouce is ready ???
              You could use a scheduled task to execute every 5 seconds (n minutes) to check the resource.


              I have a fixed number of resources (servers) set up, and put them in a queue. They are available as long as I don't use them...

              Anyway, I'm not going to leave this thread dead, and I came up with a solution... To clear things up, this is what I was trying to acheive:

              I had several servers waiting to process compression jobs(compress videos). These were accessible through webservice-interfaces.

              Initially, I set up a queue of available webservice endpoints, and had a MDB listening to that queue. When a server became available (MDB.onMessage()), I waited for a compression job (from another queue) to become available (through MessageConsumer.receive()), and then processed that job with the available server.

              The problem whas that JBoss disliked this, as I was locking the MDB thread waiting for the next job.

              Since I could not come up with a good solution for this scenario, I decided to install a JMS client on each of the compression servers. This allowed me to connect an MDB from each of the servers to the job queue.

              Despite the problem of installing a JMS client on every compression server, this was the only reasonable way I came up with to tackling this usecase. If anyone has any ideas on how to solve this without installing the JMS client on every compression server, I'd be very glad.

              Regards

              /Alex