cyfonly commented on issue #1472: 直连模式参数回调功能抛异常 URL: https://github.com/apache/incubator-dubbo/issues/1472#issuecomment-377518376 ``` public interface CallbackListener{ void change(String msg); } ``` ``` public interface CallbackService { void addListener(String key, CallbackListener listener); } ``` ``` public class CallbackServiceImpl implements CallbackService{ @Override public void addListener(String key, CallbackListener listener) { System.out.println("-------------Provider receive: key=" + key); listener.change("hehehehehe"); } } ``` ``` public class Provider { public static void main(String[] args) throws IOException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "classpath:callback_provider.xml" }); context.start(); System.in.read(); } } ``` ``` public class Consumer { public static void main(String[] args) throws IOException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:callback_consumer.xml"); context.start(); CallbackService callbackService = (CallbackService) context.getBean("callbackService"); callbackService.addListener("Chenng", new CallbackListener() { @Override public void change(String msg) { System.out.println("============Consumer reveive:msg=" + msg); } }); } } ``` consumer.xml ``` <dubbo:registry register="false"/> <dubbo:protocol name="dubbo" port="20880"/> <bean id="callbackService" class="com.dubbo.callback.CallbackServiceImpl" /> <dubbo:service interface="com.dubbo.callback.CallbackService" ref="callbackService"> <dubbo:method name="addListener"> <dubbo:argument index="1" callback="true" type="com.dubbo.callback.CallbackListener"/> </dubbo:method> </dubbo:service> ``` provider.xml `<dubbo:reference id="callbackService" interface="com.dubbo.callback.CallbackService" url="dubbo://127.0.0.1:20880"/>`
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
