public class MuleClient extends Object implements Disposable
MuleClient
is a simple interface for Mule clients to send and
receive events from a Mule Server. In most Mule applications events are triggered
by some external occurrence such as a message being received on a queue or a file
being copied to a directory. The Mule client allows the user to send and receive
events programmatically through its API.
The client defines a EndpointURI
which is used to determine how a message is
sent of received. The url defines the protocol, the endpointUri destination of the
message and optionally the endpoint to use when dispatching the event. For
example:
vm://my.object
dispatches to a my.object
destination
using the VM endpoint. There needs to be a global VM endpoint registered for the
message to be sent.
jms://jmsProvider/orders.topic
dispatches a JMS message via the
globally registered jmsProvider over a topic destination called
orders.topic
.
jms://orders.topic
is equivalent to the above except that the
endpoint is determined by the protocol, so the first JMS endpoint is used.
Note that there must be a configured MuleManager for this client to work. It will
use the one available using muleContext
MuleEndpointURI
Modifier and Type | Field and Description |
---|---|
protected static Log |
logger
logger used by this class
|
PHASE_NAME
Modifier | Constructor and Description |
---|---|
protected |
MuleClient()
Creates a Mule client that will use the default serverEndpoint when connecting to a remote
server instance.
|
|
MuleClient(boolean startContext) |
|
MuleClient(MuleContext context) |
|
MuleClient(String configResources)
Configures a Mule client instance using the the default
SpringXmlConfigurationBuilder to parse configResources . |
|
MuleClient(String configResources,
ConfigurationBuilder builder)
Configures a Mule client instance
|
|
MuleClient(String configResources,
ConfigurationBuilder builder,
String user,
String password)
Configures a Mule client instance
|
|
MuleClient(String user,
String password)
Configures a new Mule client and either uses an existing Manager running in
this JVM or creates a new empty
MuleContext |
Modifier and Type | Method and Description |
---|---|
void |
dispatch(String url,
MuleMessage message)
Dispatches an event asynchronously to a endpointUri via a Mule server.
|
void |
dispatch(String url,
Object payload,
Map<String,Object> messageProperties)
Dispatches an event asynchronously to a endpointUri via a Mule server.
|
void |
dispatchDirect(String componentName,
MuleMessage message)
Deprecated.
|
void |
dispatchDirect(String component,
Object payload,
Map<String,Object> messageProperties)
Deprecated.
|
void |
dispose()
Will dispose the MuleManager instance if a new instance was created for this
client.
|
MuleConfiguration |
getConfiguration() |
protected InboundEndpoint |
getDefaultClientEndpoint(Service service,
Object payload,
boolean sync) |
protected MuleEvent |
getEvent(MuleMessage message,
MessageExchangePattern exchangePattern) |
protected InboundEndpoint |
getInboundEndpoint(String uri) |
MuleContext |
getMuleContext()
The overriding method may want to return a custom
MuleContext here |
protected OutboundEndpoint |
getOutboundEndpoint(String uri,
MessageExchangePattern exchangePattern,
Integer responseTimeout) |
Object |
getProperty(String key) |
RemoteDispatcher |
getRemoteDispatcher(String serverEndpoint)
Deprecated.
|
RemoteDispatcher |
getRemoteDispatcher(String serverEndpoint,
String user,
String password)
Deprecated.
|
void |
registerComponent(Object component,
String name,
EndpointURI listenerEndpoint)
Deprecated.
Use the RegistryContext to get the registry and register the
service there
|
void |
registerComponent(Object component,
String name,
MuleEndpointURI listenerEndpoint,
MuleEndpointURI sendEndpoint)
Deprecated.
Use the RegistryContext to get the registry and register the
service there
|
MuleMessage |
request(String url,
List<?> transformers,
long timeout)
Will receive an event from an endpointUri determined by the URL
|
MuleMessage |
request(String url,
long timeout)
Will receive an event from an endpointUri determined by the URL.
|
MuleMessage |
request(String url,
String transformers,
long timeout)
Will receive an event from an endpointUri determined by the URL
|
MuleMessage |
send(String url,
MuleMessage message)
Sends an event synchronously to a endpointUri via a Mule server and a
resulting message is returned.
|
MuleMessage |
send(String url,
MuleMessage message,
int timeout)
Sends an event synchronously to a endpointUri via a mule server and a
resulting message is returned.
|
MuleMessage |
send(String url,
Object payload,
Map<String,Object> messageProperties)
Sends an event synchronously to a endpointUri via a Mule server and a
resulting message is returned.
|
MuleMessage |
send(String url,
Object payload,
Map<String,Object> messageProperties,
int timeout)
Sends an event synchronously to a endpointUri via a mule server and a
resulting message is returned.
|
FutureMessageResult |
sendAsync(String url,
MuleMessage message)
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.
|
FutureMessageResult |
sendAsync(String url,
MuleMessage message,
int 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.
|
FutureMessageResult |
sendAsync(String url,
Object payload,
Map<String,Object> messageProperties)
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.
|
FutureMessageResult |
sendAsync(String url,
Object payload,
Map<String,Object> messageProperties,
int 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.
|
MuleMessage |
sendDirect(String componentName,
String transformers,
MuleMessage message)
Deprecated.
|
MuleMessage |
sendDirect(String component,
String transformers,
Object payload,
Map<String,Object> messageProperties)
Deprecated.
|
FutureMessageResult |
sendDirectAsync(String component,
String transformers,
MuleMessage message)
Deprecated.
|
FutureMessageResult |
sendDirectAsync(String component,
String transformers,
Object payload,
Map<String,Object> messageProperties)
Deprecated.
|
void |
sendNoReceive(String url,
Object payload,
Map<String,Object> messageProperties)
Sends an event synchronously to a endpointUri via a Mule server without
waiting for the result.
|
void |
setProperty(String key,
Object value) |
void |
unregisterComponent(String name)
Deprecated.
Use the RegistryContext to get the registry and unregister the
service there
|
protected static final Log logger
protected MuleClient() throws MuleException
MuleException
public MuleClient(boolean startContext) throws MuleException
MuleException
public MuleClient(MuleContext context) throws MuleException
MuleException
public MuleClient(String configResources) throws MuleException
SpringXmlConfigurationBuilder
to parse configResources
.configResources
- a config resource location to configure this client
withConfigurationException
- if there is a MuleContext
instance already
running in this JVM or if the builder fails to configure the
ManagerMuleException
public MuleClient(String user, String password) throws MuleException
MuleContext
user
- the username to use when connecting to a remote server instancepassword
- the password for the userMuleException
public MuleClient(String configResources, ConfigurationBuilder builder) throws ConfigurationException, InitialisationException
configResources
- a config resource location to configure this client
withbuilder
- the configuration builder to useConfigurationException
- is there is a MuleContext
instance already
running in this JVM or if the builder fails to configure the
ManagerInitialisationException
public MuleClient(String configResources, ConfigurationBuilder builder, String user, String password) throws ConfigurationException, InitialisationException
configResources
- a config resource location to configure this client
withbuilder
- the configuration builder to useuser
- the username to use when connecting to a remote server instancepassword
- the password for the userConfigurationException
- is there is a MuleContext
instance already
running in this JVM or if the builder fails to configure the
ManagerInitialisationException
public void dispatch(String url, Object payload, Map<String,Object> messageProperties) throws MuleException
url
- the Mule URL used to determine the destination and transport of the
messagepayload
- the object that is the payload of the eventmessageProperties
- any properties to be associated with the payload. In
the case of JMS you could set the JMSReplyTo property in these
properties.MuleException
public void dispatch(String url, MuleMessage message) throws MuleException
url
- the Mule URL used to determine the destination and transport of the
messagemessage
- the message to sendMuleException
@Deprecated public MuleMessage sendDirect(String component, String transformers, Object payload, Map<String,Object> messageProperties) throws MuleException
component
- the name of the Mule component to send totransformers
- a comma separated list of transformers to apply to the
result messagepayload
- the object that is the payload of the eventmessageProperties
- any properties to be associated with the payload. as
nullMuleException
- if the dispatch fails or the components or
transfromers cannot be found
Deprecated from 3.6.0 - Only supported with Services. Sending message to remote flows is not supported.@Deprecated public MuleMessage sendDirect(String componentName, String transformers, MuleMessage message) throws MuleException
componentName
- the name of the Mule component to send totransformers
- a comma separated list of transformers to apply to the
result messagemessage
- the message to sendMuleException
- if the dispatch fails or the components or
transfromers cannot be found
Deprecated from 3.6.0 - Only supported with Services. Sending message to remote flows is not supported.@Deprecated public void dispatchDirect(String component, Object payload, Map<String,Object> messageProperties) throws MuleException
component
- the name of the Mule components to dispatch topayload
- the object that is the payload of the eventmessageProperties
- any properties to be associated with the payload. as
nullMuleException
- if the dispatch fails or the components or
transfromers cannot be found
Deprecated from 3.6.0 - Only supported with Services. Sending message to remote flows is not supported.@Deprecated public void dispatchDirect(String componentName, MuleMessage message) throws MuleException
componentName
- the name of the Mule components to dispatch tomessage
- the message to sendMuleException
- if the dispatch fails or the components or
transfromers cannot be found
Deprecated from 3.6.0 - Only supported with Services. Sending message to remote flows is not supported.public FutureMessageResult sendAsync(String url, Object payload, Map<String,Object> messageProperties) throws MuleException
url
- the url to make a request onpayload
- the object that is the payload of the eventmessageProperties
- any properties to be associated with the payload. as
nullMuleException
- if the dispatch fails or the components or
transfromers cannot be foundpublic FutureMessageResult sendAsync(String url, MuleMessage message) throws MuleException
url
- the URL to make a request onmessage
- the message to sendMuleException
- if the dispatch fails or the components or
transfromers cannot be foundpublic FutureMessageResult sendAsync(String url, Object payload, Map<String,Object> messageProperties, int timeout) throws MuleException
url
- the url to make a request onpayload
- the object that is the payload of the eventmessageProperties
- any properties to be associated with the payload. as
nulltimeout
- how long to block in milliseconds waiting for a resultMuleException
- if the dispatch fails or the components or
transfromers cannot be foundpublic FutureMessageResult sendAsync(String url, MuleMessage message, int timeout) throws MuleException
url
- the url to make a request onmessage
- the message to sendtimeout
- how long to block in milliseconds waiting for a resultMuleException
- if the dispatch fails or the components or
transfromers cannot be found@Deprecated public FutureMessageResult sendDirectAsync(String component, String transformers, Object payload, Map<String,Object> messageProperties) throws MuleException
tcp://localhost:60504
is used.component
- the name of the Mule components to send totransformers
- a comma separated list of transformers to apply to the
result messagepayload
- the object that is the payload of the eventmessageProperties
- any properties to be associated with the payload.MuleException
- if the dispatch fails or the components or
transfromers cannot be found
Deprecated from 3.6.0 - Only supported with Services. Sending message to remote flows is not supported.@Deprecated public FutureMessageResult sendDirectAsync(String component, String transformers, MuleMessage message) throws MuleException
tcp://localhost:60504
is used.component
- the name of the Mule components to send totransformers
- a comma separated list of transformers to apply to the
result messagemessage
- the message to sendMuleException
- if the dispatch fails or the components or
transfromers cannot be found
Deprecated from 3.6.0 - Only supported with Services. Sending message to remote flows is not supported.public MuleMessage send(String url, Object payload, Map<String,Object> messageProperties) throws MuleException
url
- the Mule URL used to determine the destination and transport of the
messagepayload
- the object that is the payload of the eventmessageProperties
- any properties to be associated with the payload. In
the case of Jms you could set the JMSReplyTo property in these
properties.null
if the the components invoked
explicitly sets a return as null
.MuleException
public MuleMessage send(String url, MuleMessage message) throws MuleException
url
- the Mule URL used to determine the destination and transport of the
messagemessage
- the Message for the eventnull
if the the components invoked
explicitly sets a return as null
.MuleException
public MuleMessage send(String url, Object payload, Map<String,Object> messageProperties, int timeout) throws MuleException
url
- the Mule URL used to determine the destination and transport of the
messagepayload
- the object that is the payload of the eventmessageProperties
- any properties to be associated with the payload. In
the case of Jms you could set the JMSReplyTo property in these
properties.timeout
- The time in milliseconds the the call should block waiting for
a responsenull
if the the components invoked
explicitly sets a return as null
.MuleException
public MuleMessage send(String url, MuleMessage message, int timeout) throws MuleException
url
- the Mule URL used to determine the destination and transport of the
messagemessage
- The message to sendtimeout
- The time in milliseconds the the call should block waiting for
a responsenull
if the the components invoked
explicitly sets a return as null
.MuleException
public MuleMessage request(String url, long timeout) throws MuleException
url
- the Mule URL used to determine the destination and transport of the
messagetimeout
- 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
forevernull
if no message was receivedMuleException
public MuleMessage request(String url, String transformers, long timeout) throws MuleException
url
- the Mule URL used to determine the destination and transport of the
messagetransformers
- A comma separated list of transformers used to apply to
the result messagetimeout
- 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
forevernull
if no message was receivedMuleException
public MuleMessage request(String url, List<?> transformers, long timeout) throws MuleException
url
- the Mule URL used to determine the destination and transport of the
messagetransformers
- Transformers used to modify the result messagetimeout
- 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
forevernull
if no message was receivedMuleException
protected MuleEvent getEvent(MuleMessage message, MessageExchangePattern exchangePattern) throws MuleException
MuleException
protected InboundEndpoint getInboundEndpoint(String uri) throws MuleException
MuleException
protected OutboundEndpoint getOutboundEndpoint(String uri, MessageExchangePattern exchangePattern, Integer responseTimeout) throws MuleException
MuleException
protected InboundEndpoint getDefaultClientEndpoint(Service service, Object payload, boolean sync) throws MuleException
MuleException
public void sendNoReceive(String url, Object payload, Map<String,Object> messageProperties) throws MuleException
url
- the Mule URL used to determine the destination and transport of the
messagepayload
- the object that is the payload of the eventmessageProperties
- any properties to be associated with the payload. In
the case of Jms you could set the JMSReplyTo property in these
properties.MuleException
public MuleContext getMuleContext()
MuleContext
here@Deprecated public void registerComponent(Object component, String name, EndpointURI listenerEndpoint) throws MuleException
component
- any java object, Mule will it's endpointUri discovery to
determine which event to invoke based on the evnet payload typename
- The identifying name of the components. This can be used to later
unregister itlistenerEndpoint
- The url endpointUri to listen toMuleException
@Deprecated public void registerComponent(Object component, String name, MuleEndpointURI listenerEndpoint, MuleEndpointURI sendEndpoint) throws MuleException
component
- any java object, Mule will it's endpointUri discovery to
determine which event to invoke based on the evnet payload typename
- The identifying name of the components. This can be used to later
unregister itlistenerEndpoint
- The url endpointUri to listen tosendEndpoint
- The url endpointUri to dispatch toMuleException
@Deprecated public void unregisterComponent(String name) throws MuleException
name
- the name of the componet to unregisterMuleException
- if unregistering the components fails, i.e. The
underlying transport fails to unregister a listener. If the
components does not exist, this method should not throw an
exception.Model
@Deprecated public RemoteDispatcher getRemoteDispatcher(String serverEndpoint) throws MuleException
MuleException
@Deprecated public RemoteDispatcher getRemoteDispatcher(String serverEndpoint, String user, String password) throws MuleException
MuleException
public void dispose()
dispose
in interface Disposable
public MuleConfiguration getConfiguration()
Copyright © 2003–2016 MuleSoft, Inc.. All rights reserved.