List of usage examples for javax.jms JMSException JMSException
public JMSException(String reason)
From source file:org.apache.jmeter.protocol.jms.sampler.PublisherSampler.java
/** * The implementation will publish n messages within a for loop. Once n * messages are published, it sets the attributes of SampleResult. * * @return the populated sample result/*from w w w .jav a2s. c o m*/ */ @Override public SampleResult sample() { SampleResult result = new SampleResult(); result.setSampleLabel(getName()); result.setSuccessful(false); // Assume it will fail result.setResponseCode("000"); // ditto $NON-NLS-1$ if (publisher == null) { try { initClient(); } catch (JMSException e) { result.setResponseMessage(e.toString()); return result; } catch (NamingException e) { result.setResponseMessage(e.toString()); return result; } } StringBuilder buffer = new StringBuilder(); StringBuilder propBuffer = new StringBuilder(); int loop = getIterationCount(); result.sampleStart(); String type = getMessageChoice(); try { Map<String, Object> msgProperties = getJMSProperties().getJmsPropertysAsMap(); int deliveryMode = getUseNonPersistentDelivery() ? DeliveryMode.NON_PERSISTENT : DeliveryMode.PERSISTENT; int priority = Integer.parseInt(getPriority()); long expiration = Long.parseLong(getExpiration()); for (int idx = 0; idx < loop; idx++) { if (JMSPublisherGui.TEXT_MSG_RSC.equals(type)) { String tmsg = getMessageContent(); Message msg = publisher.publish(tmsg, getDestination(), msgProperties, deliveryMode, priority, expiration); buffer.append(tmsg); Utils.messageProperties(propBuffer, msg); } else if (JMSPublisherGui.MAP_MSG_RSC.equals(type)) { Map<String, Object> m = getMapContent(); Message msg = publisher.publish(m, getDestination(), msgProperties, deliveryMode, priority, expiration); Utils.messageProperties(propBuffer, msg); } else if (JMSPublisherGui.OBJECT_MSG_RSC.equals(type)) { Serializable omsg = getObjectContent(); Message msg = publisher.publish(omsg, getDestination(), msgProperties, deliveryMode, priority, expiration); Utils.messageProperties(propBuffer, msg); } else if (JMSPublisherGui.BYTES_MSG_RSC.equals(type)) { byte[] bmsg = getBytesContent(); Message msg = publisher.publish(bmsg, getDestination(), msgProperties, deliveryMode, priority, expiration); Utils.messageProperties(propBuffer, msg); } else { throw new JMSException(type + " is not recognised"); } } result.setResponseCodeOK(); result.setResponseMessage(loop + " messages published"); result.setSuccessful(true); result.setSamplerData(buffer.toString()); result.setSampleCount(loop); result.setRequestHeaders(propBuffer.toString()); } catch (Exception e) { result.setResponseMessage(e.toString()); } finally { result.sampleEnd(); } return result; }
From source file:org.apache.rocketmq.jms.DeliverMessageService.java
private void pullMessage() throws Exception { Set<MessageQueue> mqs = this.rocketMQPullConsumer.fetchSubscribeMessageQueues(this.topicName); for (MessageQueue mq : mqs) { Long offset = offsetMap.get(mq); if (offset == null) { offset = beginOffset(mq);//from w ww . jav a2 s .co m } PullResult pullResult = this.rocketMQPullConsumer.pullBlockIfNotFound(mq, this.messageSelector, offset, PULL_BATCH_SIZE); switch (pullResult.getPullStatus()) { case FOUND: List<MessageExt> msgs = pullResult.getMsgFoundList(); offsetMap.put(mq, pullResult.getMaxOffset()); for (MessageExt msg : msgs) { handleMessage(msg, mq); } log.debug("Pull {} messages from topic:{},broker:{},queueId:{}", msgs.size(), mq.getTopic(), mq.getBrokerName(), mq.getQueueId()); break; case NO_NEW_MSG: case NO_MATCHED_MSG: break; case OFFSET_ILLEGAL: throw new JMSException("Error during pull message[reason:OFFSET_ILLEGAL]"); } } }
From source file:org.apache.rocketmq.jms.DeliverMessageService.java
/** * If {@link #consumeModel} is {@link ConsumeModel#ASYNC}, messages pulled from broker * are handled in {@link ConsumeMessageService} owned by its session. * * If {@link #consumeModel} is {@link ConsumeModel#SYNC}, messages pulled from broker are put * into a memory blocking queue, waiting for the {@link MessageConsumer#receive()} * using {@link BlockingQueue#poll()} to handle messages synchronous. * * @param msg to handle message//from w ww .j av a 2 s . co m * @throws InterruptedException * @throws JMSException */ private void handleMessage(MessageExt msg, MessageQueue mq) throws InterruptedException, JMSException { Message jmsMessage = MessageConverter.convert2JMSMessage(msg); final MessageWrapper wrapper = new MessageWrapper(jmsMessage, this.consumer, mq, msg.getQueueOffset()); switch (this.consumeModel) { case SYNC: this.msgQueue.put(wrapper); break; case ASYNC: this.consumer.getSession().getConsumeMessageService().put(wrapper); break; default: throw new JMSException(format("Unsupported consume model[%s]", this.consumeModel)); } }
From source file:org.apache.rocketmq.jms.DeliverMessageService.java
public void ack(MessageQueue mq, Long offset) throws JMSException { try {//from ww w.ja v a 2 s. c om this.rocketMQPullConsumer.updateConsumeOffset(mq, offset); } catch (MQClientException e) { throw new JMSException(format("Fail to ack offset[mq:%s,offset:%s]", mq, offset)); } }
From source file:org.apache.rocketmq.jms.DeliverMessageService.java
public MessageWrapper poll() throws JMSException { try {// ww w . ja v a2s. c o m return this.msgQueue.take(); } catch (InterruptedException e) { throw new JMSException(e.getMessage()); } }
From source file:org.apache.rocketmq.jms.DeliverMessageService.java
public MessageWrapper poll(long timeout, TimeUnit timeUnit) throws JMSException { try {// w ww .j av a 2s.c o m return this.msgQueue.poll(timeout, timeUnit); } catch (InterruptedException e) { throw new JMSException(e.getMessage()); } }
From source file:org.apache.rocketmq.jms.RocketMQConnection.java
@Override public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException { //todo: support transacted and more acknowledge mode if (transacted) { throw new JMSException("Not support local transaction session"); }/*from w w w .j av a 2s.c o m*/ if (acknowledgeMode != AUTO_ACKNOWLEDGE) { throw new JMSException("Only support AUTO_ACKNOWLEDGE mode now"); } RocketMQSession session = new RocketMQSession(this, acknowledgeMode, transacted); this.sessionList.add(session); return session; }
From source file:org.apache.rocketmq.jms.RocketMQConnection.java
@Override public ConnectionConsumer createConnectionConsumer(Destination destination, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException { //todo/*from w w w . j a va 2s. c o m*/ throw new JMSException("Not support yet"); }
From source file:org.apache.rocketmq.jms.RocketMQConnection.java
@Override public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException { //todo/*from w ww. j ava 2 s . c o m*/ throw new JMSException("Not support yet"); }
From source file:org.apache.rocketmq.jms.RocketMQConnection.java
@Override public ConnectionConsumer createSharedConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException { //todo//from w w w . j a va 2 s .c o m throw new JMSException("Not support yet"); }