Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improvement] Do not throw error for Temporary Topic/Queue creation and deletion without admin privileges #154

Merged
merged 7 commits into from
Nov 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,7 @@ public TemporaryQueue createTemporaryQueue(PulsarSession session) throws JMSExce
checkNotClosed();
String name =
"persistent://" + factory.getSystemNamespace() + "/jms-temp-queue-" + UUID.randomUUID();
try {
factory.getPulsarAdmin().topics().createNonPartitionedTopic(name);
} catch (Exception err) {
throw Utils.handleException(err);
}
createNonPartitionedTopic(name);
PulsarTemporaryQueue res = new PulsarTemporaryQueue(name, session);
temporaryDestinations.add(res);
return res;
Expand All @@ -926,11 +922,7 @@ public TemporaryTopic createTemporaryTopic(PulsarSession session) throws JMSExce
checkNotClosed();
String name =
"persistent://" + factory.getSystemNamespace() + "/jms-temp-topic-" + UUID.randomUUID();
try {
factory.getPulsarAdmin().topics().createNonPartitionedTopic(name);
} catch (Exception err) {
throw Utils.handleException(err);
}
createNonPartitionedTopic(name);
PulsarTemporaryTopic res = new PulsarTemporaryTopic(name, session);
temporaryDestinations.add(res);
return res;
Expand Down Expand Up @@ -996,6 +988,14 @@ private ConnectionConsumer buildConnectionConsumer(
return connectionConsumer;
}

private void createNonPartitionedTopic(String name) {
try {
factory.getPulsarAdmin().topics().createNonPartitionedTopic(name);
} catch (Exception err) {
sandeep-ctds marked this conversation as resolved.
Show resolved Hide resolved
log.warn("Skipping creation of nonPartitionedTopic {}", name, err);
}
}

void refreshServerSideSelectors() {
sessions.forEach(
s -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.jms.InvalidDestinationException;
import javax.jms.JMSException;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.common.policies.data.TopicStats;

Expand All @@ -44,8 +45,14 @@ public final void delete() throws JMSException {
log.info("Deleting {}", this);
String topicName = getInternalTopicName();
String fullQualifiedTopicName = session.getFactory().applySystemNamespace(topicName);
TopicStats stats =
session.getFactory().getPulsarAdmin().topics().getStats(fullQualifiedTopicName);
PulsarAdmin pulsarAdmin;
try {
pulsarAdmin = session.getFactory().getPulsarAdmin();
} catch (Exception e) {
sandeep-ctds marked this conversation as resolved.
Show resolved Hide resolved
log.warn("Cannot delete a temporary destination {}", this, e);
return;
}
TopicStats stats = pulsarAdmin.topics().getStats(fullQualifiedTopicName);
log.info("Stats {}", stats);

int numConsumers =
Expand Down
Loading