Why can't I enqueue a message with String attributes? [message #434293] |
Tue, 08 December 2009 07:12 |
Hidden
Messages: 4 Registered: October 2008 Location: Poland
|
Junior Member |
|
|
Hello,
I have a very annoying problem when I try to enqueue a message to the selected queue. At the begining I'd like to highlight that this problem shows up only while enqueuing a message with String/VARCHAR2 attributes.
Here is the example that I use (of course it is simplified for a presentation purpose but even though it doesn't work...):
CREATE OR REPLACE TYPE DEMO_MESSAGE AS OBJECT (
notifID VARCHAR2(30)
)
BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE(
Queue_table => 'USERNAME.DEMO_TABLE',
Queue_payload_type => 'USERNAME_DEMO_MESSAGE',
storage_clause => 'PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 TABLESPACE USERS',
Sort_list => 'ENQ_TIME',
Multiple_consumers => TRUE,
Compatible => '8.1.3');
END;
BEGIN DBMS_AQADM.CREATE_QUEUE(
Queue_name => 'USERNAME.DEMO_QUEUE',
Queue_table => 'USERNAME.DEMO_TABLE',
Queue_type => 0,
Max_retries => 5,
Retry_delay => 0,
dependency_tracking => FALSE);
END;
In this queue I want to enqueue a message which type is DEMO_MESSAGE. I use Java to do this, so please take a look on the following code:
StructDescriptor structDect = new StructDescriptor(
"USERNAME.DEMO_MESSAGE", conn);
Object[] attrs = new Object[1];
attrs[0] = "Hello World";
STRUCT str = new STRUCT(structDect, conn, attrs);
message.setPayload(str);
As a result in the queue table I get USERNAME.DEMO_MESSAGE(null) in the USER_DATA column. This happens all the time, there is always null value instead "Hello World".
I also wanted to use a separate java class to construct a message payload, but again the result is still null. The following code shows my payload java class:
class DemoMessage implements ORAData, ORADataFactory
{
static final DemoMessage _demoFactory = new DemoMessage();
String notifID;
public static ORADataFactory getORADataFactory()
{
return _demoFactory;
}
public DemoMessage() {}
public DemoMessage(String _notifID)
{
this.notifID = _notifID;
}
public Datum toDatum(Connection c) throws SQLException
{
StructDescriptor sd =
StructDescriptor.createDescriptor("USERNAME.DEMO_MESSAGE", c);
Object [] attributes = { this.notifID };
return new STRUCT(sd, c, attributes);
}
public ORAData create(Datum d, int sqlType) throws SQLException
{
if (d == null) return null;
Object [] attributes = ((STRUCT) d).getOracleAttributes();
return new DemoMessage((String) attributes[0]);
}
}
And then, using this class I'm enqueuing the message:
DemoMessage demo = new DemoMessage("AAAAA");
message.setPayload((STRUCT)demo.toDatum(conn));
Again the string attribute inside DEMO_MESSAGE is null. I also tried to replace a String attribute inside DemoMessage class with oracle.sql.CHAR attribute as there was shown in the following example download-west.oracle.com/docs/cd/B28359_01/java.111/b31224/oraoot.htm#i1078205 (Person.java), but still there was no change...
Of course to construct CHAR object the characterset is needed so I checked my database charset with the following query:
SELECT value$ FROM sys.props$ WHERE name = 'NLS_CHARACTERSET' ;
As a result EE8MSWIN1250 was printed, so during construction CHAR objects I used:
new CHAR("Hello World", CharacterSet.make(CharacterSet.EE8MSWIN1250_CHARSET))
And still no change
If I changed the VARCHAR2 attribute type in the DEMO_MESSAGE to NUMBER and then use a basic int type in java class instead String, I'm able to successfully enqueue a message with a NUMBER attribute populated with the correct value (which I used in object constructor).
So my question is: what I have done wrong with the String/text attributes. Is this a matter of characterset? Is this a matter of type inconsistency?
thanks in advance!
|
|
|
|