📄 muleclient.java
字号:
MuleMessage result = event.getService().sendEvent(event); if (logger.isDebugEnabled()) { logger.debug("Result of MuleClient sendDirect is: " + (result == null ? "null" : result.getPayload())); } if (result != null && trans != null) { result.applyTransformers(trans); } return result; } /** * Dispatches an event asynchronously to a component * * @param component the name of the Mule components to dispatch to * @param payload the object that is the payload of the event * @param messageProperties any properties to be associated with the payload. as * null * @throws org.mule.api.MuleException if the dispatch fails or the components or * transfromers cannot be found */ public void dispatchDirect(String component, Object payload, Map messageProperties) throws MuleException { dispatchDirect(component, new DefaultMuleMessage(payload, messageProperties)); } /** * Dispatches an event asynchronously to a component * * @param componentName the name of the Mule components to dispatch to * @param message the message to send * @throws org.mule.api.MuleException if the dispatch fails or the components or * transfromers cannot be found */ public void dispatchDirect(String componentName, MuleMessage message) throws MuleException { Service service = muleContext.getRegistry().lookupService(componentName); if (service == null) { throw new MessagingException(CoreMessages.objectNotRegistered("Service", componentName), message); } MuleSession session = new DefaultMuleSession(service, muleContext); ImmutableEndpoint endpoint = getDefaultClientEndpoint(service, message.getPayload()); MuleEvent event = new DefaultMuleEvent(message, endpoint, session, true); if (logger.isDebugEnabled()) { logger.debug("MuleClient dispatching event direct to: " + componentName + ". MuleEvent is: " + event); } event.getService().dispatchEvent(event); } /** * Sends an event request to a URL, making the result of the event trigger * available as a Future result that can be accessed later by client code. * * @param url the url to make a request on * @param payload the object that is the payload of the event * @param messageProperties any properties to be associated with the payload. as * null * @return the result message if any of the invocation * @throws org.mule.api.MuleException if the dispatch fails or the components or * transfromers cannot be found */ public FutureMessageResult sendAsync(final String url, final Object payload, final Map messageProperties) throws MuleException { return sendAsync(url, payload, messageProperties, 0); } /** * Sends an event request to a URL, making the result of the event trigger * available as a Future result that can be accessed later by client code. * * @param url the URL to make a request on * @param message the message to send * @return the result message if any of the invocation * @throws org.mule.api.MuleException if the dispatch fails or the components or * transfromers cannot be found */ public FutureMessageResult sendAsync(final String url, final MuleMessage message) throws MuleException { return sendAsync(url, message, MuleEvent.TIMEOUT_NOT_SET_VALUE); } /** * Sends an event request to a URL, making the result of the event trigger * available as a Future result that can be accessed later by client code. * * @param url the url to make a request on * @param payload the object that is the payload of the event * @param messageProperties any properties to be associated with the payload. as * null * @param timeout how long to block in milliseconds waiting for a result * @return the result message if any of the invocation * @throws org.mule.api.MuleException if the dispatch fails or the components or * transfromers cannot be found */ public FutureMessageResult sendAsync(final String url, final Object payload, final Map messageProperties, final int timeout) throws MuleException { return sendAsync(url, new DefaultMuleMessage(payload, messageProperties), timeout); } /** * Sends an event request to a URL, making the result of the event trigger * available as a Future result that can be accessed later by client code. * * @param url the url to make a request on * @param message the message to send * @param timeout how long to block in milliseconds waiting for a result * @return the result message if any of the invocation * @throws org.mule.api.MuleException if the dispatch fails or the components or * transfromers cannot be found */ public FutureMessageResult sendAsync(final String url, final MuleMessage message, final int timeout) throws MuleException { Callable call = new Callable() { public Object call() throws Exception { return send(url, message, timeout); } }; FutureMessageResult result = new FutureMessageResult(call); if (muleContext.getWorkManager() != null) { result.setExecutor(muleContext.getWorkManager()); } result.execute(); return result; } /** * Sends an event to a component on a local Mule instance, while making the * result of the event trigger available as a Future result that can be accessed * later by client code. Users can specify a url to a remote Mule server in the * constructor of a Mule client, by default the default Mule server url * <code>tcp://localhost:60504</code> is used. * * @param component the name of the Mule components to send to * @param transformers a comma separated list of transformers to apply to the * result message * @param payload the object that is the payload of the event * @param messageProperties any properties to be associated with the payload. * @return the result message if any of the invocation * @throws org.mule.api.MuleException if the dispatch fails or the components or * transfromers cannot be found */ public FutureMessageResult sendDirectAsync(final String component, String transformers, final Object payload, final Map messageProperties) throws MuleException { return sendDirectAsync(component, transformers, new DefaultMuleMessage(payload, messageProperties)); } /** * Snds an event to a component on a local Mule instance, while making the result * of the event trigger available as a Future result that can be accessed later * by client code. Users can specify a url to a remote Mule server in the * constructor of a Mule client, by default the default Mule server url * <code>tcp://localhost:60504</code> is used. * * @param component the name of the Mule components to send to * @param transformers a comma separated list of transformers to apply to the * result message * @param message the message to send * @return the result message if any of the invocation * @throws org.mule.api.MuleException if the dispatch fails or the components or * transfromers cannot be found */ public FutureMessageResult sendDirectAsync(final String component, String transformers, final MuleMessage message) throws MuleException { Callable call = new Callable() { public Object call() throws Exception { return sendDirect(component, null, message); } }; FutureMessageResult result = new FutureMessageResult(call); if (muleContext.getWorkManager() != null) { result.setExecutor(muleContext.getWorkManager()); } if (StringUtils.isNotBlank(transformers)) { result.setTransformers(TransformerUtils.getTransformers(transformers)); } result.execute(); return result; } /** * Sends an event synchronously to a endpointUri via a Mule server and a * resulting message is returned. * * @param url the Mule URL used to determine the destination and transport of the * message * @param payload the object that is the payload of the event * @param messageProperties any properties to be associated with the payload. In * the case of Jms you could set the JMSReplyTo property in these * properties. * @return A return message, this could be <code>null</code> if the the components invoked * explicitly sets a return as <code>null</code>. * @throws org.mule.api.MuleException */ public MuleMessage send(String url, Object payload, Map messageProperties) throws MuleException { return send(url, payload, messageProperties, MuleEvent.TIMEOUT_NOT_SET_VALUE); } /** * Sends an event synchronously to a endpointUri via a Mule server and a * resulting message is returned. * * @param url the Mule URL used to determine the destination and transport of the * message * @param message the Message for the event * @return A return message, this could be <code>null</code> if the the components invoked * explicitly sets a return as <code>null</code>. * @throws org.mule.api.MuleException */ public MuleMessage send(String url, MuleMessage message) throws MuleException { return send(url, message, MuleEvent.TIMEOUT_NOT_SET_VALUE); } /** * Sends an event synchronously to a endpointUri via a mule server and a * resulting message is returned. * * @param url the Mule URL used to determine the destination and transport of the * message * @param payload the object that is the payload of the event * @param messageProperties any properties to be associated with the payload. In * the case of Jms you could set the JMSReplyTo property in these * properties. * @param timeout The time in milliseconds the the call should block waiting for * a response * @return A return message, this could be <code>null</code> if the the components invoked * explicitly sets a return as <code>null</code>. * @throws org.mule.api.MuleException */ public MuleMessage send(String url, Object payload, Map messageProperties, int timeout) throws MuleException { if (messageProperties == null) { messageProperties = new HashMap(); } if (messageProperties.get(MuleProperties.MULE_REMOTE_SYNC_PROPERTY) == null) { messageProperties.put(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, "true"); } MuleMessage message = new DefaultMuleMessage(payload, messageProperties); return send(url, message, timeout); } /** * Sends an event synchronously to a endpointUri via a mule server and a * resulting message is returned. * * @param url the Mule URL used to determine the destination and transport of the * message * @param message The message to send * @param timeout The time in milliseconds the the call should block waiting for * a response * @return A return message, this could be <code>null</code> if the the components invoked * explicitly sets a return as <code>null</code>. * @throws org.mule.api.MuleException */ public MuleMessage send(String url, MuleMessage message, int timeout) throws MuleException { MuleEvent event = getEvent(message, url, true); event.setTimeout(timeout); try { MuleMessage msg = event.getSession().sendEvent(event); if (msg == null) { msg = new DefaultMuleMessage(NullPayload.getInstance()); } return msg; } catch (MuleException e) { throw e; } catch (Exception e) { throw new DispatchException(ClientMessages.failedToDispatchClientEvent(), event.getMessage(), event.getEndpoint(), e); } } /** * Will receive an event from an endpointUri determined by the URL. * * @param url the Mule URL used to determine the destination and transport of the * message * @param timeout how long to block waiting to receive the event, if set to 0 the * receive will not wait at all and if set to -1 the receive will wait * forever * @return the message received or <code>null</code> if no message was received * @throws org.mule.api.MuleException */ public MuleMessage request(String url, long timeout) throws MuleException { InboundEndpoint endpoint = getInboundEndpoint(url); try { MuleMessage message = endpoint.request(timeout); if (message != null && endpoint.getTransformers() != null) { message.applyTransformers(endpoint.getTransformers()); } return message; } catch (Exception e) { throw new ReceiveException(endpoint, timeout, e); } } /** * Will receive an event from an endpointUri determined by the URL * * @param url the Mule URL used to determine the destination and transport of the * message * @param transformers A comma separated list of transformers used to apply to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -