如何在 CXF 生成的客户端中以编程方式更改 JMS 主题?

发布于 2025-01-01 04:09:48 字数 1655 浏览 1 评论 0原文

我有 WSDL 文件,其中包含:

    <wsdl:port name="NotificationConsumerSoapJms"
        binding="tns_NotificationConsumer:NotificationConsumerSoapJmsBinding">
        <jms:address destinationStyle="topic"
            jndiConnectionFactoryName="ConnectionFactory"
            jndiDestinationName="dynamicTopics/test.DefaultTopic">

            <jms:JMSNamingProperty name="java.naming.factory.initial"
                value="org.apache.activemq.jndi.ActiveMQInitialContextFactory" />
            <jms:JMSNamingProperty name="java.naming.provider.url"
                value="tcp://localhost:61616" />
        </jms:address>
    </wsdl:port>

这是由 CXF 生成的 JMS 客户端:

    URL wsdlURL = EfaNbiWebService.WSDL_LOCATION;
    if (args.length > 0 && args[0] != null && !"".equals(args[0])) { 
        File wsdlFile = new File(args[0]);
        try {
            if (wsdlFile.exists()) {
                wsdlURL = wsdlFile.toURI().toURL();
            } else {
                wsdlURL = new URL(args[0]);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    EfaNbiWebService ss = new EfaNbiWebService(wsdlURL, SERVICE_NAME);
    NotificationConsumer port = ss.getNotificationConsumerSoapJms();  


    {
    System.out.println("Invoking notify...");
    org.tmforum.mtop.fmw.xsd.hdr.v1.Header _notify_mtopHeader = null;
    org.tmforum.mtop.fmw.xsd.notmsg.v1.Notify _notify_mtopBody = null;
    port.notify(_notify_mtopHeader, _notify_mtopBody);


    }

如您所见,主题名称存储在 WSDL 文件中。那么如何以编程方式更改主题名称呢?

I have WSDL file which contains:

    <wsdl:port name="NotificationConsumerSoapJms"
        binding="tns_NotificationConsumer:NotificationConsumerSoapJmsBinding">
        <jms:address destinationStyle="topic"
            jndiConnectionFactoryName="ConnectionFactory"
            jndiDestinationName="dynamicTopics/test.DefaultTopic">

            <jms:JMSNamingProperty name="java.naming.factory.initial"
                value="org.apache.activemq.jndi.ActiveMQInitialContextFactory" />
            <jms:JMSNamingProperty name="java.naming.provider.url"
                value="tcp://localhost:61616" />
        </jms:address>
    </wsdl:port>

And here is JMS client which was generated by CXF:

    URL wsdlURL = EfaNbiWebService.WSDL_LOCATION;
    if (args.length > 0 && args[0] != null && !"".equals(args[0])) { 
        File wsdlFile = new File(args[0]);
        try {
            if (wsdlFile.exists()) {
                wsdlURL = wsdlFile.toURI().toURL();
            } else {
                wsdlURL = new URL(args[0]);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    EfaNbiWebService ss = new EfaNbiWebService(wsdlURL, SERVICE_NAME);
    NotificationConsumer port = ss.getNotificationConsumerSoapJms();  


    {
    System.out.println("Invoking notify...");
    org.tmforum.mtop.fmw.xsd.hdr.v1.Header _notify_mtopHeader = null;
    org.tmforum.mtop.fmw.xsd.notmsg.v1.Notify _notify_mtopBody = null;
    port.notify(_notify_mtopHeader, _notify_mtopBody);


    }

As you see, the topic name is store in WSDL file. So how to change topic name programmatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻的味道 2025-01-08 04:09:48

我找到了解决方案:

    JMSConfiguration jmsConfig = new JMSConfiguration();

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://" + activeMQServer + ":61616");
    jmsConfig.setConnectionFactory(connectionFactory);
    jmsConfig.setTargetDestination("dynamicTopics/Test.Notification_" + topic);
    jmsConfig.setReconnectOnException(false);
    //jmsConfig.se
    jmsConfig.setPubSubDomain(true);
    jmsConfig.setUseJms11(true);
    jmsConfig.setTransactionManager(new JmsTransactionManager(connectionFactory));

    JMSConfigFeature jmsConfigFeature = new JMSConfigFeature();
    jmsConfigFeature.setJmsConfig(jmsConfig);

    String address = "jms:jndi:dynamicTopics/Test.Notification_" + topic + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&jndiConnectionFactoryName=ConnectionFactory&jndiURL=tcp://" + activeMQServer + ":61616";
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    // And specify the transport ID with SOAP over JMS specification
    factory.setTransportId(JMSSpecConstants.SOAP_JMS_SPECIFICATION_TRANSPORTID);
    factory.setServiceClass(NotificationConsumer.class);
    factory.getFeatures().add(jmsConfigFeature);
    factory.setAddress(address);
    NotificationConsumer client = (NotificationConsumer)factory.create();

祝大家有美好的一天:)

I found the solution:

    JMSConfiguration jmsConfig = new JMSConfiguration();

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://" + activeMQServer + ":61616");
    jmsConfig.setConnectionFactory(connectionFactory);
    jmsConfig.setTargetDestination("dynamicTopics/Test.Notification_" + topic);
    jmsConfig.setReconnectOnException(false);
    //jmsConfig.se
    jmsConfig.setPubSubDomain(true);
    jmsConfig.setUseJms11(true);
    jmsConfig.setTransactionManager(new JmsTransactionManager(connectionFactory));

    JMSConfigFeature jmsConfigFeature = new JMSConfigFeature();
    jmsConfigFeature.setJmsConfig(jmsConfig);

    String address = "jms:jndi:dynamicTopics/Test.Notification_" + topic + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&jndiConnectionFactoryName=ConnectionFactory&jndiURL=tcp://" + activeMQServer + ":61616";
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    // And specify the transport ID with SOAP over JMS specification
    factory.setTransportId(JMSSpecConstants.SOAP_JMS_SPECIFICATION_TRANSPORTID);
    factory.setServiceClass(NotificationConsumer.class);
    factory.getFeatures().add(jmsConfigFeature);
    factory.setAddress(address);
    NotificationConsumer client = (NotificationConsumer)factory.create();

Have a nice day, guys :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文