How do I get events from a non-persistent queue?

How do I get events from a non-persistent queue?

Postby cdjahn » Thu 20 Nov 2008 16:59

How do I get events from a non-persistent queue? I can get the callback to trigger but when I try to dequeue the message I get an "ORA-25249 dequeue not allowed for queue" error.
cdjahn
 
Posts: 2
Joined: Thu 20 Nov 2008 16:51

Postby Shalex » Fri 21 Nov 2008 10:49

Could you please send me (alexsh*devart*com) a small test project to reproduce this issue?
Shalex
Devart Team
 
Posts: 7303
Joined: Thu 14 Aug 2008 12:44

Postby cdjahn » Fri 21 Nov 2008 14:57

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Devart.Common;
using Devart.Data.Oracle;

namespace NonPersistentQueueTest
{
class Program
{
private const string QUEUE_NAME = "TEST_QUEUE2";
private const string QUEUE_TABLE_NAME = "TEST_QUEUE2_TABLE";

static void Main( string[] args )
{
Program pgm = new Program();
pgm.TestAQ();
}

void TestAQ()
{
OracleConnection oracleConnection = new OracleConnection( "data source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = CJAHN-W500.hps.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE) ) );User Id=PipelineTest;Password=PipelineTest;" );
oracleConnection.Open();

OracleQueueAdmin oracleQueueAdmin = new OracleQueueAdmin( QUEUE_NAME, oracleConnection );
oracleQueueAdmin.Options.QueueType = OracleQueueType.NonPersistentMultiConsumers;
oracleQueueAdmin.CreateQueue();
oracleQueueAdmin.StartQueue();

// Register Bob and Scott as known recipients.
// This is required to send messages to Bob or Scott personally.
oracleQueueAdmin.AddSubscriber( new OracleQueueAgent( "Bob" ) );
oracleQueueAdmin.AddSubscriber( new OracleQueueAgent( "Scott" ) );

OracleQueue oracleEnqueueQueue = new OracleQueue( QUEUE_NAME, oracleConnection );
oracleEnqueueQueue.EnqueueOptions.Visibility = OracleQueueVisibility.Immediate;

// This message will be delivered to Bob only.
OracleQueueMessage message1 = new OracleQueueMessage();
message1.StringPayload = "Message for Bob.";
message1.MessageProperties.RecipientList.Add( new OracleQueueAgent( "Bob" ) );

// This message will be delivered to all recipients, as there is no specific member in the recipients list.
OracleQueueMessage message2 = new OracleQueueMessage();
message2.StringPayload = "Message for all.";

// Create an OracleQueue instance that will receive general notifications and notifications for Scott.
OracleQueue oracleDequeueScott = new OracleQueue( QUEUE_NAME, oracleConnection );
oracleDequeueScott.DequeueOptions.Navigation = OracleQueueNavigation.FirstMessage;
oracleDequeueScott.DequeueOptions.ConsumerName = "Scott";
// Set up asynchronous notification using events.
// The event just signals that a new message is available; messages are not dequeued implicitly.
oracleDequeueScott.AsyncNotification = true;
oracleDequeueScott.OnMessage += new OracleQueueMessageEventHandler( oracleDequeueScott_OnMessage );

// Create an OracleQueue instance that will receive general notifications and notifications for Bob.
OracleQueue oracleDequeueBob = new OracleQueue( QUEUE_NAME, oracleConnection );
oracleDequeueBob.DequeueOptions.Navigation = OracleQueueNavigation.FirstMessage;
oracleDequeueBob.DequeueOptions.ConsumerName = "Bob";
oracleDequeueBob.AsyncNotification = true;
oracleDequeueBob.OnMessage += new OracleQueueMessageEventHandler( oracleDequeueBob_OnMessage );

// Enqueue the messages
oracleEnqueueQueue.Enqueue( message1 );
oracleEnqueueQueue.Enqueue( message2 );

// Wait a little so the events can fire.
System.Threading.Thread.Sleep( 10000 );

Console.ReadLine();

oracleQueueAdmin.StopQueue();
oracleQueueAdmin.DropQueue();

oracleConnection.Close();
}

// A helper function that dequeues messages during an event
string getMessageData( object sender, OracleQueueMessageEventArgs e )
{
OracleQueue oracleDequeue = sender as OracleQueue;
OracleQueueDequeueOptions dequeueOptions = oracleDequeue.DequeueOptions;
dequeueOptions.MessageId = e.MessageId;
// Messages are not deleted from server once dequeued.
dequeueOptions.DequeueMode = OracleQueueDequeueMode.Browse;
OracleQueueMessage msg = oracleDequeue.Dequeue( dequeueOptions );
return msg.StringPayload;
}


// Simple event handlers that write something into console when a message is received
void oracleDequeueBob_OnMessage( object sender, OracleQueueMessageEventArgs e )
{
string messageData = getMessageData( sender, e );
Console.WriteLine( "Bob receives a message: " + messageData );
}


void oracleDequeueScott_OnMessage( object sender, OracleQueueMessageEventArgs e )
{
string messageData = getMessageData( sender, e );
Console.WriteLine( "Scott receives a message: " + messageData );
}
}
}
cdjahn
 
Posts: 2
Joined: Thu 20 Nov 2008 16:51

Postby Shalex » Mon 24 Nov 2008 15:16

Does your user have the ENQUEUE and DEQUEUE privileges on the queues?

Please specify the version of your Oracle server and the version of dotConnect for Oracle you are using.

We cannot reproduce the mentioned error on Oracle server 10.1 and dotConnect for Oracle 5.0.12.
Shalex
Devart Team
 
Posts: 7303
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle