Home » Java » How to dequeue from oracle advanced queue using java?-Exceptionshub

How to dequeue from oracle advanced queue using java?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment


My payload is a custom data type ..iam able to dequeue.But iam not able to get the values from the queue in AQCustomPayloadObject obj(onMessage) as the values in the object is coming as null…Please find my java class for the corresponding oracle type object below.Also please let me know what is integer array ‘_sqlType’ in AQCustomPayloadObject .Is there any specific value that we should give to this?

public class AQCustomPayloadObject implements ORAData, ORADataFactory {

public static final String _SQL_NAME = "AQ_EVENT_OBJ";
public static final int _SQL_TYPECODE = OracleTypes.STRUCT;

protected MutableStruct _struct;

protected static int[] _sqlType = { 91, 12, 12 };
protected static ORADataFactory[] _factory = new ORADataFactory[3];
protected static final AQCustomPayloadObject _AqEventObjFactory = new AQCustomPayloadObject();

public static ORADataFactory getORADataFactory() {
    return _AqEventObjFactory;

/* constructors */
protected void _init_struct(boolean init) {
    if (init)
        _struct = new MutableStruct(new Object[3], _sqlType, _factory);

public AQCustomPayloadObject() {

public AQCustomPayloadObject(java.sql.Timestamp datetime, String id, String payload)
        throws SQLException {

/* ORAData interface */
public Datum toDatum(Connection c) throws SQLException {
    return _struct.toDatum(c, _SQL_NAME);

/* ORADataFactory interface */
public ORAData create(Datum d, int sqlType) throws SQLException {
    return create(null, d, sqlType);

protected ORAData create(AQCustomPayloadObject o, Datum d, int sqlType)
        throws SQLException {
    if (d == null)
        return null;
    if (o == null)
        o = new AQCustomPayloadObject();
    o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);
    return o;

/* accessor methods */
public java.sql.Timestamp getDatetime() throws SQLException {
    return (java.sql.Timestamp) _struct.getAttribute(0);

public void setDatetime(java.sql.Timestamp datetime) throws SQLException {
    _struct.setAttribute(0, datetime);

public String getId() throws SQLException {
    return (String) _struct.getAttribute(1);

public void setId(String id) throws SQLException {
    _struct.setAttribute(1, id);

public String getPayload() throws SQLException {
    return (String) _struct.getAttribute(2);

public void setPayload(String payload) throws SQLException {
    _struct.setAttribute(2, payload);


public class AQCustomPayloadMessageListenerContainer extends
    DefaultMessageListenerContainer {

protected MessageConsumer createConsumer(Session session,
        Destination destination) throws JMSException {

    return ((AQjmsSession) session).createConsumer(destination,
            AQCustomPayloadObject.getORADataFactory(), null,




public class AQReceiver implements MessageListener {

private static final Logger logger = LoggerFactory

public void onMessage(Message message) {
    try {
        AQjmsAdtMessage msg = (AQjmsAdtMessage) message;
        AQCustomPayloadObject obj = (AQCustomPayloadObject) msg.getAdtPayload();

        logger.info("Id: {}", obj.getid());
        logger.info("Datetime: {}", obj.getDatetime());
        logger.info("Payload: {}", obj.getPayload());

    } catch (Exception e) {
        logger.error("Error receiving queue message!", e);


How to&Answers: