You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by gnanda1 <gi...@hotmail.com> on 2010/08/09 18:49:34 UTC

sending a message to a jbi endpoint from a custom MBean

Hi All,
I  am using smx4.2.
I have created a custom Mbean with two operations exposed. The interface is
defined as below
public interface ServiceResourceManagerMBean  {
	public void startServiceResource(String servicename, String resourcename);

	public void stopServiceResource(String servicename, String resourcename);
}
>From the jconsole when these operations get called I need to create a xml
message and post to a jbi endpoint (which is a endpoint in camel router)
I  am trying with the below code
public void startServiceResource(String servicename, String resourcename){
	log.info("startServiceResource");
	String xml = this.BuildMessage(servicename, resourcename);
	this.sendMessage(xml);
	
}

public void sendMessage(String xml) {
		try {
			log.info("sendMessage start");
			// ComponentContext context = getContext();
			InOnly exchange = context.getDeliveryChannel()
					.createExchangeFactory().createInOnlyExchange();
			NormalizedMessage message = exchange.createMessage();
			message.setContent(new StringSource(xml));
			/*
			 * EndpointResolver resolver =
			 * channel.lient.createResolverForService(service); if (resolver !=
			 * null) { ServiceEndpoint destination =
			 * resolver.resolveEndpoint(getContext(), exchange,
			 * NullEndpointFilter.getInstance());
			 * exchange.setEndpoint(destination); }
			 */
			QName service = new QName("urn:com.pf.simpleprovider", "http");

			exchange.setService(service);
			exchange.setInMessage(message);
			// Now, send the message exchange
			log.info("sendMessage before send");
exchange.setStatus(ExchangeStatus.ACTIVE);
			context.getDeliveryChannel().send(exchange);
			log.info("sendMessage end");
		} catch (Exception e) {
			log.error("error",e);
		}
	}

I am not sure  my approach here is correct or not. 
1)Could I use Deliverychannel here to send a message to a jbi endpoint?
 Or do I need get reference to servicemixClient to send a message to jbi
endpoint?

2)  Does this file need to extend messageListener class and  in onlisten()
method do need to close/complete this communication  by setting status to
DONE.
Since it is in-only exchange, I guess I do not expect any return coming
back, but not sure about it

3) I am having issue with getting reference to ComponentContext here. I have
posted the error in another thread.

I am really stuck here

Any help is greately appreciated. 
Thanks & Regards
Gnanda
 



-- 
View this message in context: http://servicemix.396122.n5.nabble.com/sending-a-message-to-a-jbi-endpoint-from-a-custom-MBean-tp2269081p2269081.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: sending a message to a jbi endpoint from a custom MBean

Posted by gnanda1 <gi...@hotmail.com>.
Thanks Freeman. I followed the nmr example and I am able to send exchange
successfully.
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/sending-a-message-to-a-jbi-endpoint-from-a-custom-MBean-tp2269081p2473471.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: sending a message to a jbi endpoint from a custom MBean

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

You need use SMX4 client api to do it.
Take a look at nmr/client example shipped with kit to get details  
about how to do it.
Now you create client channel from injected nmr service, but not the  
context, so you should not worry about the context injection in this  
case.

Freeman
On 2010-8-10, at 上午12:49, gnanda1 wrote:

>
> Hi All,
> I  am using smx4.2.
> I have created a custom Mbean with two operations exposed. The  
> interface is
> defined as below
> public interface ServiceResourceManagerMBean  {
> 	public void startServiceResource(String servicename, String  
> resourcename);
>
> 	public void stopServiceResource(String servicename, String  
> resourcename);
> }
> From the jconsole when these operations get called I need to create  
> a xml
> message and post to a jbi endpoint (which is a endpoint in camel  
> router)
> I  am trying with the below code
> public void startServiceResource(String servicename, String  
> resourcename){
> 	log.info("startServiceResource");
> 	String xml = this.BuildMessage(servicename, resourcename);
> 	this.sendMessage(xml);
> 	
> }
>
> public void sendMessage(String xml) {
> 		try {
> 			log.info("sendMessage start");
> 			// ComponentContext context = getContext();
> 			InOnly exchange = context.getDeliveryChannel()
> 					.createExchangeFactory().createInOnlyExchange();
> 			NormalizedMessage message = exchange.createMessage();
> 			message.setContent(new StringSource(xml));
> 			/*
> 			 * EndpointResolver resolver =
> 			 * channel.lient.createResolverForService(service); if (resolver !=
> 			 * null) { ServiceEndpoint destination =
> 			 * resolver.resolveEndpoint(getContext(), exchange,
> 			 * NullEndpointFilter.getInstance());
> 			 * exchange.setEndpoint(destination); }
> 			 */
> 			QName service = new QName("urn:com.pf.simpleprovider", "http");
>
> 			exchange.setService(service);
> 			exchange.setInMessage(message);
> 			// Now, send the message exchange
> 			log.info("sendMessage before send");
> exchange.setStatus(ExchangeStatus.ACTIVE);
> 			context.getDeliveryChannel().send(exchange);
> 			log.info("sendMessage end");
> 		} catch (Exception e) {
> 			log.error("error",e);
> 		}
> 	}
>
> I am not sure  my approach here is correct or not.
> 1)Could I use Deliverychannel here to send a message to a jbi  
> endpoint?
> Or do I need get reference to servicemixClient to send a message to  
> jbi
> endpoint?
>
> 2)  Does this file need to extend messageListener class and  in  
> onlisten()
> method do need to close/complete this communication  by setting  
> status to
> DONE.
> Since it is in-only exchange, I guess I do not expect any return  
> coming
> back, but not sure about it
>
> 3) I am having issue with getting reference to ComponentContext  
> here. I have
> posted the error in another thread.
>
> I am really stuck here
>
> Any help is greately appreciated.
> Thanks & Regards
> Gnanda
>
>
>
>
> -- 
> View this message in context: http://servicemix.396122.n5.nabble.com/sending-a-message-to-a-jbi-endpoint-from-a-custom-MBean-tp2269081p2269081.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


-- 
Freeman Fang

------------------------
Open Source SOA: http://fusesource.com
Apache Servicemix:http://servicemix.apache.org
Apache Cxf: http://cxf.apache.org
Apache Karaf: http://karaf.apache.org
Apache Felix: http://felix.apache.org