All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datastax.oss.pulsar.jms.PulsarJMSConsumer Maven / Gradle / Ivy

/*
 * Copyright DataStax, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.datastax.oss.pulsar.jms;

import jakarta.jms.JMSConsumer;
import jakarta.jms.JMSRuntimeException;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;

public class PulsarJMSConsumer implements JMSConsumer {

  private final PulsarMessageConsumer pulsarMessageConsumer;

  public PulsarJMSConsumer(PulsarMessageConsumer pulsarMessageConsumer) {
    this.pulsarMessageConsumer = pulsarMessageConsumer;
  }

  public PulsarMessageConsumer asPulsarMessageConsumer() {
    return pulsarMessageConsumer;
  }

  @Override
  public String getMessageSelector() {
    return Utils.runtimeException(() -> pulsarMessageConsumer.getMessageSelector());
  }

  @Override
  public MessageListener getMessageListener() throws JMSRuntimeException {
    return Utils.runtimeException(() -> pulsarMessageConsumer.getMessageListener());
  }

  @Override
  public void setMessageListener(MessageListener listener) throws JMSRuntimeException {
    Utils.runtimeException(() -> pulsarMessageConsumer.setMessageListener(listener));
  }

  @Override
  public Message receive() {
    return Utils.runtimeException(() -> pulsarMessageConsumer.receive());
  }

  @Override
  public Message receive(long timeout) {
    return Utils.runtimeException(() -> pulsarMessageConsumer.receive(timeout));
  }

  @Override
  public Message receiveNoWait() {
    return Utils.runtimeException(() -> pulsarMessageConsumer.receiveNoWait());
  }

  @Override
  public void close() {
    Utils.runtimeException(() -> pulsarMessageConsumer.close());
  }

  @Override
  public  T receiveBody(Class c) {
    return Utils.runtimeException(
        () -> {
          Message msg = pulsarMessageConsumer.receiveWithTimeoutAndValidateType(Long.MAX_VALUE, c);
          return msg == null ? null : msg.getBody(c);
        });
  }

  @Override
  public  T receiveBody(Class c, long timeout) {
    return Utils.runtimeException(
        () -> {
          Message msg = pulsarMessageConsumer.receiveWithTimeoutAndValidateType(timeout, c);
          return msg == null ? null : msg.getBody(c);
        });
  }

  @Override
  public  T receiveBodyNoWait(Class c) {
    return Utils.runtimeException(
        () -> {
          Message msg = pulsarMessageConsumer.receiveWithTimeoutAndValidateType(1, c);
          return msg == null ? null : msg.getBody(c);
        });
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy