Hi  justin

Thanks , I am able to achieve  HA  by xml  as well as   API also. I was
missing the connector  configuration.

 New Requirement:-
i want to  enable the web console in artemis 2.19.1.  What are the steps I
need to do.
I am using  embbededActivemq.java to start the artemis.

Thanks
Niraj



On Wed, Apr 9, 2025 at 8:40 AM Justin Bertram <jbert...@apache.org> wrote:

> In the code you shared I don't see any evidence that you're properly
> configuring your brokers to cluster. A pair of brokers using replication
> need a valid cluster to discover each other. This is noted in the
> documentation [1] which states, "A proper cluster configuration is required
> as a pre-requisite for an HA configuration."
>
> Instead of attempting to configure the broker via the configuration API
> would it be possible for you to put a broker.xml file on your classpath?
> That would save you a lot of time and effort, and it would be much more
> flexible if you ever needed to change the configuration.
>
> In any case, take a look at one of the replicated examples [2] as a
> template for what you need to configure.
>
>
> Justin
>
> [1]
>
> https://activemq.apache.org/components/artemis/documentation/latest/ha.html#ha-policies
> [2]
>
> https://github.com/apache/activemq-artemis-examples/tree/main/examples/features/ha
>
> On Tue, Apr 8, 2025 at 9:07 PM Niraj Kumar Rohit <
> nirajkumarro...@gmail.com>
> wrote:
>
> > Hi
> >
> >
> > USE CASE:--
> > 1.We have one app which run in two server DP1 AND DP2
> > 2.Both DP1 and DP2 using embedded EmbeddedActiveMQ.java API to run apache
> > activemq artemis.
> > 3.if i  start  DP1 1st then it is become live server and  DP2 become
> >  backup and vice versa
> > 4.Now i shutdown DP1  then  DP2 should live  and as i start DP1 it beahve
> > as backup  till DP2 not fail.
> > 5.in this case of artemis after fail of DP1,   DP2 is not behaving as
> live
> > server. because after failover of  DP1 , DP2 is not get activate .i am
> > checking  like this and always traped into loop nver come out from the
> > loop.
> >
> >  while
> > (!jmsServer.getActiveMQServer().waitForActivation(30L,TimeUnit.SECONDS))
> {
> >             Thread.sleep(100);
> >
> >         }
> > 6.API using for live and backup  server
> >
> >         if (isCurrentServerLive){
> >             ReplicatedPolicyConfiguration haPolicy = new
> > ReplicatedPolicyConfiguration();
> >             haPolicy.setGroupName("bsm-back-up-group");
> >             haPolicy.setInitialReplicationSyncTimeout(120000);
> >             haPolicy.setCheckForLiveServer(true);  // Critical for
> failover
> > detection
> >             haPolicy.setQuorumSize(1);  // Minimum nodes required
> >             configuration.setHAPolicyConfiguration(haPolicy);
> >          }else{
> >             ReplicaPolicyConfiguration haPolicy = new
> > ReplicaPolicyConfiguration();
> >             haPolicy.setGroupName("bsm-back-up-group");
> >             haPolicy.setInitialReplicationSyncTimeout(120000);
> >             haPolicy.setRestartBackup(false);  // Don't restart when live
> > exists
> >             haPolicy.setAllowFailBack(true);  // Allow primary to resume
> >             configuration.setHAPolicyConfiguration(haPolicy);;
> >
> >           }
> >
> >
> > 7.even listern is also not getting  call , listner implemation  in backup
> > side
> > public void  registerListener(boolean isCurrentServerLive) {
> >         LOG.info("kutt registerListener "+(!isCurrentServerLive?"back
> going
> > to register Listner":"live server not going to register"));
> >         if (!isCurrentServerLive) {
> >             final ActiveMQServer artemisServer =
> > jmsServer.getActiveMQServer();
> >             LOG.info(" registerListener done");
> >             artemisServer.registerActivateCallback(new ActivateCallback()
> >
> >             {
> >                 @Override
> >                 public void preActivate() {
> >
> >                     LOG.info(" registerListener preActivate() called");
> >                 }
> >
> >                 @Override
> >                 public void deActivate() {
> >                     LOG.info(" registerListener deActivate() called");
> >                 }
> >
> >                 @Override
> >                 public void activationComplete() {
> >                     LOG.info(" registerListener activationComplete()
> > called");
> >                 }
> >
> >
> >                 @Override
> >                 public void activated() {
> >                     LOG.info(" registerListener activated() called");
> >
> >
> >                     // Below changes to check if the live bus is really
> > active.
> >                     // read the server state initially see the last
> > interval
> >                     // loop of 2 times of interval
> >                     // wait of interval for 1 second
> >                     // read the state and see if the state changes
> >                     // if there is change then without changing the live
> > bus then restart
> >                     // if there is no change then update the live server
> > and then restart
> >                     try {
> >                         long busState = busData.getServerState();
> >                         int maxChecks = 10;
> >                         boolean isLiveBusActive = false;
> >
> >                         synchronized (this) {
> >                             while (!isLiveBusActive && (maxChecks > 0)) {
> >                                 wait(1000L);
> >
> >                                 isLiveBusActive = (busState !=
> > busData.getServerState());
> >                                 LOG.info(" listerner called now on
> failover
> >  with state of backup"+isLiveBusActive);
> >                                 maxChecks--;
> >                             }
> >                         }
> >
> >                         if (!isLiveBusActive)
> >                             busData.setLiveServer(socket);
> >                     } catch (Exception e) {
> >                         LOG.info("Failed to update live server after
> backup
> > server got activated", e);
> >                     }
> >
> >                     LOG.info("restarting backup server before clients
> fail
> > over");
> >                      try{
> >                      HornetQRunner.main(new String[]{"strat"});
> >                      }catch(Exception e){
> >                          LOG.info("faled to satrt");
> >                     }
> >
> >                     // Throwing IllegalStateException to make sure the
> > calling old jmsserver doesn't finish it's failover
> >                     // since it had been stopped and a new one has been
> > started,
> >                     throw new IllegalStateException("Need to restart
> > instead of activation");
> >                 }
> >             });
> >         }
> >
> >     }
> >
> >
> >
> >
> > i need your suggestion to make it work . and thanks in advance for your
> > help.
> >
> > its very urgent  our dead line is very near
> >
> > Thanks
> > Niraj
> >
>

Reply via email to