webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  User datagram protocol connectivity on webmethods

    Posted Tue June 10, 2025 09:26 AM

    Hi Team,

    We are looking for a way to integrate UDP(User datagram protocol) with our current infra where we have IS/MSR, API Gateway and UM.

    Any suggestion on how can we integrate UDP with webmethods components. This protocol can be on either consumer or provider side.

    Any help on this topic is highly appreciated. Please let me know if any other details are needed.

    Thanks



    ------------------------------
    Rohit Dabas
    ------------------------------


  • 2.  RE: User datagram protocol connectivity on webmethods

    Posted Tue June 10, 2025 09:37 AM
    There are a couple of ways to do this. Nothing in the product directly supports UDP. There is an old legacy package called WmSockets that allowed you to open sockets and use those. But I am not sure how available or supportable that is now. And I am not even sure how much of it was geared to support UDP. But you could create your own services to use DatagramSockets to open up server and client connections. Off course, you would not get the benefit of access control and all the other port features. But depending upon your usecase, you could connect and exchange information with minimal effort. And perhaps you can implement the Access Control on the services that process the data. No ideal but doable.


    ------------------------------
    Rupinder Singh
    CTO, Nibble Technologies
    https://www.nibl.tech/
    ------------------------------



  • 3.  RE: User datagram protocol connectivity on webmethods

    Posted Tue June 10, 2025 10:16 AM

    Hi Rupinder,

    Thank you for your reply, looks like WmSockets option is not compatible now.

    I wanted to add further here that our use case if for live data streaming. Can we use webSockets in API gateway for same.

    Thanks



    ------------------------------
    Rohit Dabas
    ------------------------------



  • 4.  RE: User datagram protocol connectivity on webmethods

    Posted Wed June 11, 2025 08:39 PM
    Edited by Moacy Barbosa Wed June 11, 2025 08:40 PM

    My 2 cents that I think might be a doable option:

    • Create a java class for continuous UDP listening within your custom package:
      package com.yourcompany.udp;
      
      import java.net.DatagramPacket;
      import java.net.DatagramSocket;
      import java.util.concurrent.atomic.AtomicBoolean;
      
      import com.wm.app.b2b.server.Service;
      import com.wm.data.IData;
      import com.wm.data.IDataFactory;
      
      public class UDPListener implements Runnable {
      
          private int port;
          private Thread thread;
          private AtomicBoolean running = new AtomicBoolean(false);
          private DatagramSocket socket;
      
          public UDPListener(int port) {
              this.port = port;
          }
      
          public void start() {
              if (running.get()) return;
              running.set(true);
              thread = new Thread(this, "UDPListenerThread");
              thread.start();
          }
      
          public void stop() {
              running.set(false);
              if (socket != null && !socket.isClosed()) {
                  socket.close();  // This will break .receive()
              }
          }
      
          @Override
          public void run() {
              try {
                  socket = new DatagramSocket(port);
                  byte[] buffer = new byte[2048];
                  while (running.get()) {
                      DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
                      socket.receive(packet);
      
                      String message = new String(packet.getData(), 0, packet.getLength());
      
                      // Invoke IS service to handle the message
                      IData input = IDataFactory.create();
                      input.getCursor().insertAfter("message", message);
                      Service.doInvoke("YourPackage.YourFolder", "handleUDPMessage", input);
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              } finally {
                  if (socket != null && !socket.isClosed()) {
                      socket.close();
                  }
              }
          }
      }
      
    • Then create 2 Java Services that will start and shutdown the UDP listener following the IS/MSR lifecycle.
      
      import com.yourcompany.udp.UDPListener;
      
      String portStr = (String) IDataUtil.get(pipelineCursor, "port");
      int port = Integer.parseInt(portStr);
      
      UDPListener listener = new UDPListener(port);
      listener.start();
      
      
    • // be aware you must implement a Singleton Listener in order to handle the Listener instances propertly.
      
      if (MyListenerHolder.listener != null) {
          MyListenerHolder.listener.stop();
      }
      

    Finally, just set up the above Java services as your custom package's startup and shutdown services, respectively.

    I know there are a few hard coded variables in the above implementation but I bet you can make it better starting from this point.

    HIH,

    Moacy  



    ------------------------------
    Moacy Barbosa
    ------------------------------