Java Code Examples for javax.jms.Message#getStringProperty()
The following examples show how to use
javax.jms.Message#getStringProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MappingJackson2MessageConverter.java From java-technology-stack with MIT License | 6 votes |
/** * Determine a Jackson JavaType for the given JMS Message, * typically parsing a type id message property. * <p>The default implementation parses the configured type id property name * and consults the configured type id mapping. This can be overridden with * a different strategy, e.g. doing some heuristics based on message origin. * @param message the JMS Message to set the type id on * @throws JMSException if thrown by JMS methods * @see #setTypeIdOnMessage(Object, javax.jms.Message) * @see #setTypeIdPropertyName(String) * @see #setTypeIdMappings(java.util.Map) */ protected JavaType getJavaTypeForMessage(Message message) throws JMSException { String typeId = message.getStringProperty(this.typeIdPropertyName); if (typeId == null) { throw new MessageConversionException( "Could not find type id property [" + this.typeIdPropertyName + "] on message [" + message.getJMSMessageID() + "] from destination [" + message.getJMSDestination() + "]"); } Class<?> mappedClass = this.idClassMappings.get(typeId); if (mappedClass != null) { return this.objectMapper.getTypeFactory().constructType(mappedClass); } try { Class<?> typeClass = ClassUtils.forName(typeId, this.beanClassLoader); return this.objectMapper.getTypeFactory().constructType(typeClass); } catch (Throwable ex) { throw new MessageConversionException("Failed to resolve type id [" + typeId + "]", ex); } }
Example 2
Source File: StaticSelectorExample.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void onMessage(final Message msg) { TextMessage textMessage = (TextMessage) msg; try { String colorProp = msg.getStringProperty("color"); System.out.println("Receiver " + name + " receives message [" + textMessage.getText() + "] with color property: " + colorProp); if (colorProp != null && !colorProp.equals(name)) { result.set(false); } } catch (JMSException e) { e.printStackTrace(); result.set(false); } }
Example 3
Source File: SpanCacheMDB.java From hawkular-apm with Apache License 2.0 | 6 votes |
@Override public void onMessage(Message message) { if (log.isLoggable(Level.FINEST)) { log.finest("Message received=" + message); } try { String tenantId = message.getStringProperty("tenant"); String data = ((TextMessage) message).getText(); List<Span> items = mapper.readValue(data, typeRef); spanCache.store(tenantId, items, SpanUniqueIdGenerator::toUnique); } catch (JMSException | IOException | CacheException e) { log.log(Level.SEVERE, "Failed to process message", e); } }
Example 4
Source File: SourceInfoCacheMDB.java From hawkular-apm with Apache License 2.0 | 6 votes |
@Override public void onMessage(Message message) { if (log.isLoggable(Level.FINEST)) { log.finest("Message received=" + message); } try { String tenantId = message.getStringProperty("tenant"); String data = ((TextMessage) message).getText(); List<Trace> items = mapper.readValue(data, typeRef); List<SourceInfo> sourceInfoList = SourceInfoUtil.getSourceInfo(tenantId, items); sourceInfoCache.store(tenantId, sourceInfoList); } catch (JMSException | IOException | CacheException | RetryAttemptException e) { log.log(Level.SEVERE, "Failed to handle message", e); } }
Example 5
Source File: QueueSelectorExample.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void onMessage(final Message msg) { TextMessage textMessage = (TextMessage) msg; try { String colorProp = msg.getStringProperty("color"); System.out.println("Receiver " + name + " receives message [" + textMessage.getText() + "] with color property: " + colorProp); if (!colorProp.equals(name) && !name.equals("any")) { result.set(false); } } catch (JMSException e) { e.printStackTrace(); result.set(false); } }
Example 6
Source File: JMSConsumer.java From oneops with Apache License 2.0 | 5 votes |
private void addData(Message message, String text) throws JMSException { MessageData data = new MessageData(); data.setPayload(text); Map<String, String> headers = new HashMap<>(); Enumeration<String> names = message.getPropertyNames(); while (names.hasMoreElements()) { String name = names.nextElement(); String value = message.getStringProperty(name); headers.put(name, value); } data.setHeaders(headers); messages.add(data); }
Example 7
Source File: MessageGroupCloseTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void checkMessage(Message m, String consumerId, Map<String, Integer> messageGroups, Set<String> closedGroups) throws JMSException { String groupId = m.getStringProperty("JMSXGroupID"); int seq = m.getIntProperty("JMSXGroupSeq"); Integer count = messageGroups.get(groupId); if (count == null) { // first time seeing this group if (!m.propertyExists("JMSXGroupFirstForConsumer") || !m.getBooleanProperty("JMSXGroupFirstForConsumer")) { LOG.info(consumerId + ": JMSXGroupFirstForConsumer not set for group=" + groupId + ", seq=" + seq); errorCountFirstForConsumer++; } if (seq == -1) { closedGroups.add(groupId); LOG.info(consumerId + ": wrong consumer got close message for group=" + groupId); errorCountWrongConsumerClose++; } messageGroups.put(groupId, 1); } else { // existing group if (closedGroups.contains(groupId)) { // group reassigned to same consumer closedGroups.remove(groupId); if (!m.propertyExists("JMSXGroupFirstForConsumer") || !m.getBooleanProperty("JMSXGroupFirstForConsumer")) { LOG.info(consumerId + ": JMSXGroupFirstForConsumer not set for group=" + groupId + ", seq=" + seq); errorCountFirstForConsumer++; } if (seq == -1) { LOG.info(consumerId + ": consumer got duplicate close message for group=" + groupId); errorCountDuplicateClose++; } } if (seq == -1) { closedGroups.add(groupId); } messageGroups.put(groupId, count + 1); } }
Example 8
Source File: BDBAMQP10V0UpgradeTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Test public void testRecoverAmqpV0Message() throws Exception { Connection connection = getConnectionBuilder().setVirtualHost("test").build(); try { connection.start(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue("queue"); MessageConsumer consumer = session.createConsumer(queue); Message message = consumer.receive(getReceiveTimeout()); assertThat("Recovered message not received", message, is(instanceOf(BytesMessage.class))); BytesMessage bytesMessage = ((BytesMessage) message); long length = bytesMessage.getBodyLength(); String expectedContentHash = message.getStringProperty("sha256hash"); byte[] content = new byte[(int) length]; bytesMessage.readBytes(content); assertThat("Unexpected content length", length, is(equalTo(EXPECTED_MESSAGE_LENGTH))); assertThat("Message should carry expectedShaHash property", expectedContentHash, is(notNullValue())); String contentHash = computeContentHash(content); assertThat("Unexpected content hash", expectedContentHash, is(equalTo(contentHash))); session.commit(); } finally { connection.close(); } }
Example 9
Source File: CoordinatorClient.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
private boolean processMessages(RemoteBroker remoteBroker) { try { Message message = remoteBroker.coordinatorConsumer.receiveNoWait(); if (message == null) { return false; } OperationType operationType = OperationType.fromInt(message.getIntProperty("operationType")); String operationData = message.getStringProperty("payload"); SimulatorOperation op = OperationCodec.fromJson(operationData, operationType.getClassType()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Received " + op); } SimulatorAddress source = SimulatorAddress.fromString(message.getStringProperty("source")); processor.process(op, source, EmptyPromise.INSTANCE); return true; } catch (Exception e) { if (!stop) { //todo: feed into failure collector LOGGER.fatal(e.getMessage(), e); } return false; } }
Example 10
Source File: DurableSubProcessConcurrentCommitActivateNoDuplicateTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void onServerMessage(Message message) throws JMSException { if (Boolean.TRUE.equals(message.getObjectProperty("COMMIT"))) { if (Boolean.TRUE.equals(message.getObjectProperty("RELEVANT"))) waitingList.add(message); } else { String messageType = message.getStringProperty("TYPE"); if (clientType.isRelevant(messageType)) waitingList.add(message); } }
Example 11
Source File: DurableSubProcessTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void onServerMessage(Message message) throws JMSException { if (Boolean.TRUE.equals(message.getObjectProperty("COMMIT"))) { if (Boolean.TRUE.equals(message.getObjectProperty("RELEVANT"))) waitingList.add(message); } else { String messageType = message.getStringProperty("TYPE"); if (clientType.isRelevant(messageType)) waitingList.add(message); } }
Example 12
Source File: AbstractPreservesMessageProperties.java From spring-cloud-ribbon-extensions with Apache License 2.0 | 5 votes |
/** * Copies the message property to the current execution context. failing silently when an exception is thrown. * * @param context the ribbon context * @param message the jms message * @param propertyName the property name to copy * @param collected the propagationProperties that have been copied */ private void copy(ExecutionContext context, Message message, String propertyName, List<String> collected) { try { String decoded = encoder.decode(propertyName); if (filter.accept(decoded)) { String value = message.getStringProperty(propertyName); context.put(decoded, value); collected.add(decoded); } } catch (JMSException e) { log.debug("Failed to copy message property [{}]", propertyName); } }
Example 13
Source File: JmsMessagePropertyAccessor.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Nullable @Override public String getFirstHeader(String headerName, Message message) { headerName = jmsifyHeaderName(headerName); String value = null; try { value = message.getStringProperty(headerName); } catch (JMSException e) { logger.error("Failed to extract JMS message property", e); } return value; }
Example 14
Source File: Server.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
private void handle() throws Exception { Message message = consumer.receive(); OperationType operationType = OperationType.fromInt(message.getIntProperty("operationType")); String operationData = message.getStringProperty("payload"); SimulatorOperation op = OperationCodec.fromJson(operationData, operationType.getClassType()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Received operation:" + op); } PromiseImpl promise = new PromiseImpl(); promise.replyTo = message.getJMSReplyTo(); promise.correlationId = message.getJMSCorrelationID(); promise.op = op; SimulatorAddress source = SimulatorAddress.fromString(message.getStringProperty("source")); try { processor.process(op, source, promise); } catch (Exception e) { if (stop) { throw e; } else { LOGGER.warn(e.getMessage(), e); promise.answer(e); } } }
Example 15
Source File: MessageGroupNewConsumerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public String formatMessage(Message m) { try { return m.getStringProperty("JMSXGroupID") + "-" + m.getIntProperty("JMSXGroupSeq") + "-" + m.getBooleanProperty("JMSXGroupFirstForConsumer"); } catch (Exception e) { return e.getClass().getSimpleName() + ": " + e.getMessage(); } }
Example 16
Source File: JMSMessageHeadersType.java From cxf with Apache License 2.0 | 5 votes |
private void readProperties(Message message) throws JMSException { Enumeration<String> enm = CastUtils.cast(message.getPropertyNames()); while (enm.hasMoreElements()) { String name = enm.nextElement(); String val = message.getStringProperty(name); String unescapedName = name.replace("__", "."); putProperty(unescapedName, val); } }
Example 17
Source File: LastValueQueueTest.java From qpid-broker-j with Apache License 2.0 | 4 votes |
private void putMessageInMap(Message message, Map<String, Integer> messageSequenceNumbersByKey) throws JMSException { String keyValue = message.getStringProperty(KEY_PROPERTY); Integer messageSequenceNumber = message.getIntProperty(MESSAGE_SEQUENCE_NUMBER_PROPERTY); messageSequenceNumbersByKey.put(keyValue, messageSequenceNumber); }
Example 18
Source File: MQSelectorUtil.java From Thunder with Apache License 2.0 | 4 votes |
public static String getResponseSelector(Message message) throws JMSException { return message.getStringProperty(SelectorType.RESPONSE_SELECTOR.toString()); }
Example 19
Source File: StompEmbeddedWithInterceptorExample.java From activemq-artemis with Apache License 2.0 | 4 votes |
public static void main(final String[] args) throws Exception { // Step 1. Create a TCP socket to connect to the Stomp port try (Socket socket = new Socket("localhost", 61616)) { // Step 2. Send a CONNECT frame to connect to the server String connectFrame = "CONNECT\n" + "accept-version:1.2\n" + "host:localhost\n" + "login:guest\n" + "passcode:guest\n" + "request-id:1\n" + "\n" + END_OF_FRAME; sendFrame(socket, connectFrame); // Step 3. Send a SEND frame (a Stomp message) to the // jms.queue.exampleQueue address with a text body String text = "Hello World from Stomp 1.2 !"; String message = "SEND\n" + "destination:exampleQueue" + "\n" + text + END_OF_FRAME; sendFrame(socket, message); System.out.println("Sent Stomp message: " + text); // Step 4. Send a DISCONNECT frame to disconnect from the server String disconnectFrame = "DISCONNECT\n" + "\n" + END_OF_FRAME; sendFrame(socket, disconnectFrame); } // It will use a regular JMS connection to show how the injected data will appear at the final message try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); Connection connection = factory.createConnection(); Session session = connection.createSession()) { connection.start(); MessageConsumer consumer = session.createConsumer(session.createQueue("exampleQueue")); Message messageReceived = consumer.receive(5000); String propStomp = messageReceived.getStringProperty("stompIntercepted"); String propRegular = messageReceived.getStringProperty("regularIntercepted"); System.out.println("propStomp is Hello!! - " + propStomp.equals("Hello")); System.out.println("propRegular is HelloAgain!! - " + propRegular.equals("HelloAgain")); } }
Example 20
Source File: SearchClientProxy.java From olat with Apache License 2.0 | 4 votes |
/** * Uses Request/reply mechanism for synchronous operation. * */ public SearchResults doSearch(final String queryString, final List<String> condQueries, final Identity identity, final Roles roles, final int firstResult, final int maxResults, final boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException { if (log.isDebugEnabled()) { log.debug("STARTqueryString=" + queryString); } final SearchRequest searchRequest = new SearchRequest(queryString, condQueries, identity.getKey(), roles, firstResult, maxResults, doHighlighting); Session session = null; try { session = acquireSession(); if (log.isDebugEnabled()) { log.debug("doSearch session=" + session); } final Message requestMessage = session.createObjectMessage(searchRequest); final Message returnedMessage = doSearchRequest(session, requestMessage); queryCount_++; if (returnedMessage != null) { final String responseStatus = returnedMessage.getStringProperty(JMS_RESPONSE_STATUS_PROPERTY_NAME); if (responseStatus.equalsIgnoreCase(JMS_RESPONSE_STATUS_OK)) { final SearchResults searchResult = (SearchResults) ((ObjectMessage) returnedMessage).getObject(); if (log.isDebugEnabled()) { log.debug("ENDqueryString=" + queryString); } return searchResult; } else if (responseStatus.equalsIgnoreCase(JMS_RESPONSE_STATUS_PARSE_EXCEPTION)) { throw new ParseException("can not parse query=" + queryString); } else if (responseStatus.equalsIgnoreCase(JMS_RESPONSE_STATUS_QUERY_EXCEPTION)) { throw new QueryException("invalid query=" + queryString); } else if (responseStatus.equalsIgnoreCase(JMS_RESPONSE_STATUS_SERVICE_NOT_AVAILABLE_EXCEPTION)) { throw new ServiceNotAvailableException("Remote search service not available" + queryString); } else { log.warn("doSearch: receive unkown responseStatus=" + responseStatus); return null; } } else { // null returnedMessage throw new ServiceNotAvailableException("communication error with JMS - cannot receive messages!!!"); } } catch (final JMSException e) { log.error("Search failure I", e); throw new ServiceNotAvailableException("communication error with JMS - cannot send messages!!!"); } finally { releaseSession(session); } }